Skip to content

Commit 2ed98ad

Browse files
committed
Don't use imageNamed which retains memory forever, closes neilang#34.
1 parent db6db0d commit 2ed98ad

9 files changed

+42
-27
lines changed

Demo/Demo/NAAnimatedDemoViewController.m

+2-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ - (void)viewDidLoad
2222
mapView.backgroundColor = [UIColor colorWithRed:0.000f green:0.475f blue:0.761f alpha:1.000f];
2323
mapView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
2424

25-
[mapView displayMap:[UIImage imageNamed:@"Maps/australia"]];
25+
NSString *australia = [[[NSBundle mainBundle] bundlePath] stringByAppendingString:@"/Maps/australia.png"];
26+
[mapView displayMap:[UIImage imageWithContentsOfFile:australia]];
2627

2728
mapView.minimumZoomScale = 0.5f;
2829
mapView.maximumZoomScale = 1.5f;

Demo/Demo/NADotAnnotationDemoViewController.m

+3-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@ - (void)viewDidLoad
2525
mapView.minimumZoomScale = 0.5f;
2626
mapView.maximumZoomScale = 1.5f;
2727

28-
[mapView displayMap:[UIImage imageNamed:@"Maps/australia"]];
28+
NSString *australia = [[[NSBundle mainBundle] bundlePath] stringByAppendingString:@"/Maps/australia.png"];
29+
UIImage *image = [UIImage imageWithContentsOfFile:australia];
30+
[mapView displayMap:image];
2931

3032
[self.view addSubview:mapView];
3133

Demo/Demo/NAInteractiveDemoViewController.m

+3-2
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,12 @@ - (void)viewDidLoad
2525

2626
self.annotations = [[NSMutableArray alloc] init];
2727

28-
UIImage *image = [UIImage imageNamed:@"Maps/australia"];
29-
3028
self.mapView.backgroundColor = [UIColor colorWithRed:0.000f green:0.475f blue:0.761f alpha:1.000f];
3129
self.mapView.mapViewDelegate = self;
3230

31+
NSString *australia = [[[NSBundle mainBundle] bundlePath] stringByAppendingString:@"/Maps/australia.png"];
32+
UIImage *image = [UIImage imageWithContentsOfFile:australia];
33+
3334
[self.mapView displayMap:image];
3435

3536
[self mapView:self.mapView hasChangedZoomLevel:self.mapView.zoomLevel];

Demo/Demo/NALoadViaNIBDemoViewController.m

+3-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ - (void)viewDidLoad
1515
{
1616
[super viewDidLoad];
1717

18-
[self.mapView displayMap:[UIImage imageNamed:@"Maps/australia"]];
18+
NSString *australia = [[[NSBundle mainBundle] bundlePath] stringByAppendingString:@"/Maps/australia.png"];
19+
UIImage *image = [UIImage imageWithContentsOfFile:australia];
20+
[self.mapView displayMap:image];
1921

2022
self.mapView.backgroundColor = [UIColor colorWithRed:0.000f green:0.475f blue:0.761f alpha:1.000f];
2123

Demo/Demo/NAPinAnnotationsDemoViewController.m

+2-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ - (void)viewDidLoad
2525
mapView.minimumZoomScale = 0.5f;
2626
mapView.maximumZoomScale = 1.5f;
2727

28-
[mapView displayMap:[UIImage imageNamed:@"Maps/australia"]];
28+
NSString *australia = [[[NSBundle mainBundle] bundlePath] stringByAppendingString:@"/Maps/australia.png"];
29+
[mapView displayMap:[UIImage imageWithContentsOfFile:australia]];
2930

3031
[self.view addSubview:mapView];
3132

Demo/Demo/NATiledImageDemoViewController.m

+4-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,10 @@ - (void)viewDidLoad
3636
mapView.backgroundColor = [UIColor colorWithRed:0.000f green:0.475f blue:0.761f alpha:1.000f];
3737
mapView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
3838
mapView.displayTileBorders = YES;
39-
// mapView.backgroundImage = [UIImage imageNamed:@"Maps/Armory2014/large.jpg"];
39+
40+
// NSString *background = [[[NSBundle mainBundle] bundlePath] stringByAppendingString:@"/Maps/Armory2014/large.jpg"];
41+
// mapView.backgroundImage = [UIImage imageWithContentsOfFile:background];
42+
4043
mapView.zoomStep = 3.0f;
4144
_mapView = mapView;
4245

Demo/Demo/main.m

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// Demo
44
//
55
// Created by Neil Ang on 6/05/12.
6-
// Copyright (c) 2012 __MyCompanyName__. All rights reserved.
6+
// Copyright (c) 2010-14 neilang.com. All rights reserved.
77
//
88

99
#import <UIKit/UIKit.h>

NAMapKit/NAPinAnnotationCallOutView.m

+13-13
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@
2020
const CGFloat NAMapViewAnnotationCalloutRightAccessoryLeftOffset = 2.0f;
2121
const CGFloat NAMapViewAnnotationCalloutRightAccessoryTopOffset = 9.0f;
2222
const CGFloat NAMapViewAnnotationCalloutAnchorYOffset = 26.0f;
23-
static NSString *NAMapViewAnnotationCalloutImageLeft = @"callout_left.png";
24-
static NSString *NAMapViewAnnotationCalloutImageRight = @"callout_right.png";
25-
static NSString *NAMapViewAnnotationCalloutImageAnchor = @"callout_anchor.png";
26-
static NSString *NAMapViewAnnotationCalloutImageBG = @"callout_bg.png";
23+
static NSString *NAMapViewAnnotationCalloutImageLeft = @"/callout_left.png";
24+
static NSString *NAMapViewAnnotationCalloutImageRight = @"/callout_right.png";
25+
static NSString *NAMapViewAnnotationCalloutImageAnchor = @"/callout_anchor.png";
26+
static NSString *NAMapViewAnnotationCalloutImageBG = @"/callout_bg.png";
2727

2828
@interface NAPinAnnotationCallOutView()
2929

@@ -32,11 +32,11 @@ @interface NAPinAnnotationCallOutView()
3232
@property (nonatomic, strong) UIImageView *calloutAnchorView;
3333
@property (nonatomic, strong) UIImageView *calloutLeftCenterView;
3434
@property (nonatomic, strong) UIImageView *calloutRightCenterView;
35-
@property (nonatomic, strong) UILabel *subtitleLabel;
36-
@property (nonatomic, strong) UILabel *titleLabel;
37-
@property (nonatomic, assign) CGPoint point;
38-
@property (nonatomic, assign) CGPoint position;
39-
@property (nonatomic, weak) NAMapView *mapView;
35+
@property (nonatomic, strong) UILabel *subtitleLabel;
36+
@property (nonatomic, strong) UILabel *titleLabel;
37+
@property (nonatomic, assign) CGPoint point;
38+
@property (nonatomic, assign) CGPoint position;
39+
@property (nonatomic, weak) NAMapView *mapView;
4040

4141
- (void)positionView:(UIView *)view posX:(float)x;
4242
- (void)positionView:(UIView *)view posX:(float)x width:(float)width;
@@ -49,10 +49,10 @@ - (id)initOnMapView:(NAMapView *)mapView
4949
{
5050
self = [super init];
5151
if (self) {
52-
UIImage *calloutBG = [[UIImage imageNamed:NAMapViewAnnotationCalloutImageBG] stretchableImageWithLeftCapWidth:0 topCapHeight:0];
53-
self.calloutLeftCapView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:NAMapViewAnnotationCalloutImageLeft]];
54-
self.calloutRightCapView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:NAMapViewAnnotationCalloutImageRight]];
55-
self.calloutAnchorView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:NAMapViewAnnotationCalloutImageAnchor]];
52+
UIImage *calloutBG = [[UIImage imageWithContentsOfFile:[[[NSBundle mainBundle] bundlePath] stringByAppendingString:NAMapViewAnnotationCalloutImageBG]] stretchableImageWithLeftCapWidth:0 topCapHeight:0];
53+
self.calloutLeftCapView = [[UIImageView alloc] initWithImage:[UIImage imageWithContentsOfFile:[[[NSBundle mainBundle] bundlePath] stringByAppendingString:NAMapViewAnnotationCalloutImageLeft]]];
54+
self.calloutRightCapView = [[UIImageView alloc] initWithImage:[UIImage imageWithContentsOfFile:[[[NSBundle mainBundle] bundlePath] stringByAppendingString:NAMapViewAnnotationCalloutImageRight]]];
55+
self.calloutAnchorView = [[UIImageView alloc] initWithImage:[UIImage imageWithContentsOfFile:[[[NSBundle mainBundle] bundlePath] stringByAppendingString:NAMapViewAnnotationCalloutImageAnchor]]];
5656
self.calloutLeftCenterView = [[UIImageView alloc] initWithImage:calloutBG];
5757
self.calloutRightCenterView = [[UIImageView alloc] initWithImage:calloutBG];
5858
self.subtitleLabel = [[UILabel alloc] initWithFrame:CGRectZero];

NAMapKit/NAPinAnnotationView.m

+11-6
Original file line numberDiff line numberDiff line change
@@ -34,22 +34,27 @@ - (void)setAnimating:(BOOL)animating
3434
{
3535
_animating = animating;
3636

37-
NSString *pinImage;
37+
NSString *pinImageName;
3838
switch (self.annotation.color) {
3939
case NAPinColorGreen:
40-
pinImage = @"pin_green";
40+
pinImageName = @"pin_green";
4141
break;
4242
case NAPinColorPurple:
43-
pinImage = @"pin_purple";
43+
pinImageName = @"pin_purple";
4444
break;
4545
case NAPinColorRed:
46-
pinImage = @"pin_red";
46+
pinImageName = @"pin_red";
4747
break;
4848
}
4949

50-
NSString * image = _animating ? [NSString stringWithFormat:@"%@_floating", pinImage] : pinImage;
50+
if (animating) {
51+
pinImageName = [NSString stringWithFormat:@"%@_floating", pinImageName];
52+
}
53+
54+
pinImageName = [NSString stringWithFormat:@"/%@.png", pinImageName];
5155

52-
[self setImage:[UIImage imageNamed:image] forState:UIControlStateNormal];
56+
UIImage *pinImage = [UIImage imageWithContentsOfFile:[[[NSBundle mainBundle] bundlePath] stringByAppendingString:pinImageName]];
57+
[self setImage:pinImage forState:UIControlStateNormal];
5358
}
5459

5560
- (void)updatePosition

0 commit comments

Comments
 (0)