|
@@ -34,39 +34,39 @@ typedef enum { |
|
@@ -34,39 +34,39 @@ typedef enum { |
34
|
@implementation RMUserTrackingBarButtonItem
|
34
|
@implementation RMUserTrackingBarButtonItem
|
35
|
|
35
|
|
36
|
@synthesize mapView = _mapView;
|
36
|
@synthesize mapView = _mapView;
|
37
|
-@synthesize segmentedControl;
|
|
|
38
|
-@synthesize buttonImageView;
|
|
|
39
|
-@synthesize activityView;
|
|
|
40
|
-@synthesize state;
|
37
|
+@synthesize segmentedControl = _segmentedControl;
|
|
|
38
|
+@synthesize buttonImageView = _buttonImageView;
|
|
|
39
|
+@synthesize activityView = _activityView;
|
|
|
40
|
+@synthesize state = _state;
|
41
|
|
41
|
|
42
|
- (id)initWithMapView:(RMMapView *)mapView
|
42
|
- (id)initWithMapView:(RMMapView *)mapView
|
43
|
{
|
43
|
{
|
44
|
if ( ! (self = [super initWithCustomView:[[UIControl alloc] initWithFrame:CGRectMake(0, 0, 32, 32)]]))
|
44
|
if ( ! (self = [super initWithCustomView:[[UIControl alloc] initWithFrame:CGRectMake(0, 0, 32, 32)]]))
|
45
|
return nil;
|
45
|
return nil;
|
46
|
|
46
|
|
47
|
- segmentedControl = [[[UISegmentedControl alloc] initWithItems:[NSArray arrayWithObject:@""]] retain];
|
|
|
48
|
- segmentedControl.segmentedControlStyle = UISegmentedControlStyleBar;
|
|
|
49
|
- [segmentedControl setWidth:32.0 forSegmentAtIndex:0];
|
|
|
50
|
- segmentedControl.userInteractionEnabled = NO;
|
|
|
51
|
- segmentedControl.tintColor = self.tintColor;
|
|
|
52
|
- segmentedControl.center = self.customView.center;
|
47
|
+ _segmentedControl = [[[UISegmentedControl alloc] initWithItems:[NSArray arrayWithObject:@""]] retain];
|
|
|
48
|
+ _segmentedControl.segmentedControlStyle = UISegmentedControlStyleBar;
|
|
|
49
|
+ [_segmentedControl setWidth:32.0 forSegmentAtIndex:0];
|
|
|
50
|
+ _segmentedControl.userInteractionEnabled = NO;
|
|
|
51
|
+ _segmentedControl.tintColor = self.tintColor;
|
|
|
52
|
+ _segmentedControl.center = self.customView.center;
|
53
|
|
53
|
|
54
|
- [self.customView addSubview:segmentedControl];
|
54
|
+ [self.customView addSubview:_segmentedControl];
|
55
|
|
55
|
|
56
|
- buttonImageView = [[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"TrackingLocation.png"]] retain];
|
|
|
57
|
- buttonImageView.contentMode = UIViewContentModeCenter;
|
|
|
58
|
- buttonImageView.frame = CGRectMake(0, 0, 32, 32);
|
|
|
59
|
- buttonImageView.center = self.customView.center;
|
|
|
60
|
- buttonImageView.userInteractionEnabled = NO;
|
56
|
+ _buttonImageView = [[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"TrackingLocation.png"]] retain];
|
|
|
57
|
+ _buttonImageView.contentMode = UIViewContentModeCenter;
|
|
|
58
|
+ _buttonImageView.frame = CGRectMake(0, 0, 32, 32);
|
|
|
59
|
+ _buttonImageView.center = self.customView.center;
|
|
|
60
|
+ _buttonImageView.userInteractionEnabled = NO;
|
61
|
|
61
|
|
62
|
- [self.customView addSubview:buttonImageView];
|
62
|
+ [self.customView addSubview:_buttonImageView];
|
63
|
|
63
|
|
64
|
- activityView = [[[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite] retain];
|
|
|
65
|
- activityView.hidesWhenStopped = YES;
|
|
|
66
|
- activityView.center = self.customView.center;
|
|
|
67
|
- activityView.userInteractionEnabled = NO;
|
64
|
+ _activityView = [[[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite] retain];
|
|
|
65
|
+ _activityView.hidesWhenStopped = YES;
|
|
|
66
|
+ _activityView.center = self.customView.center;
|
|
|
67
|
+ _activityView.userInteractionEnabled = NO;
|
68
|
|
68
|
|
69
|
- [self.customView addSubview:activityView];
|
69
|
+ [self.customView addSubview:_activityView];
|
70
|
|
70
|
|
71
|
[((UIControl *)self.customView) addTarget:self action:@selector(changeMode:) forControlEvents:UIControlEventTouchUpInside];
|
71
|
[((UIControl *)self.customView) addTarget:self action:@selector(changeMode:) forControlEvents:UIControlEventTouchUpInside];
|
72
|
|
72
|
|
|
@@ -75,7 +75,7 @@ typedef enum { |
|
@@ -75,7 +75,7 @@ typedef enum { |
75
|
[_mapView addObserver:self forKeyPath:@"userTrackingMode" options:NSKeyValueObservingOptionNew context:nil];
|
75
|
[_mapView addObserver:self forKeyPath:@"userTrackingMode" options:NSKeyValueObservingOptionNew context:nil];
|
76
|
[_mapView addObserver:self forKeyPath:@"userLocation.location" options:NSKeyValueObservingOptionNew context:nil];
|
76
|
[_mapView addObserver:self forKeyPath:@"userLocation.location" options:NSKeyValueObservingOptionNew context:nil];
|
77
|
|
77
|
|
78
|
- state = RMUserTrackingButtonStateLocation;
|
78
|
+ _state = RMUserTrackingButtonStateLocation;
|
79
|
|
79
|
|
80
|
[self updateAppearance];
|
80
|
[self updateAppearance];
|
81
|
|
81
|
|
|
@@ -84,9 +84,9 @@ typedef enum { |
|
@@ -84,9 +84,9 @@ typedef enum { |
84
|
|
84
|
|
85
|
- (void)dealloc
|
85
|
- (void)dealloc
|
86
|
{
|
86
|
{
|
87
|
- [segmentedControl release]; segmentedControl = nil;
|
|
|
88
|
- [buttonImageView release]; buttonImageView = nil;
|
|
|
89
|
- [activityView release]; activityView = nil;
|
87
|
+ [_segmentedControl release]; _segmentedControl = nil;
|
|
|
88
|
+ [_buttonImageView release]; _buttonImageView = nil;
|
|
|
89
|
+ [_activityView release]; _activityView = nil;
|
90
|
[_mapView removeObserver:self forKeyPath:@"userTrackingMode"];
|
90
|
[_mapView removeObserver:self forKeyPath:@"userTrackingMode"];
|
91
|
[_mapView removeObserver:self forKeyPath:@"userLocation.location"];
|
91
|
[_mapView removeObserver:self forKeyPath:@"userLocation.location"];
|
92
|
[_mapView release]; _mapView = nil;
|
92
|
[_mapView release]; _mapView = nil;
|
|
@@ -116,7 +116,7 @@ typedef enum { |
|
@@ -116,7 +116,7 @@ typedef enum { |
116
|
{
|
116
|
{
|
117
|
[super setTintColor:newTintColor];
|
117
|
[super setTintColor:newTintColor];
|
118
|
|
118
|
|
119
|
- segmentedControl.tintColor = newTintColor;
|
119
|
+ _segmentedControl.tintColor = newTintColor;
|
120
|
}
|
120
|
}
|
121
|
|
121
|
|
122
|
#pragma mark -
|
122
|
#pragma mark -
|
|
@@ -132,7 +132,7 @@ typedef enum { |
|
@@ -132,7 +132,7 @@ typedef enum { |
132
|
{
|
132
|
{
|
133
|
// "selection" state
|
133
|
// "selection" state
|
134
|
//
|
134
|
//
|
135
|
- segmentedControl.selectedSegmentIndex = (_mapView.userTrackingMode == RMUserTrackingModeNone ? UISegmentedControlNoSegment : 0);
|
135
|
+ _segmentedControl.selectedSegmentIndex = (_mapView.userTrackingMode == RMUserTrackingModeNone ? UISegmentedControlNoSegment : 0);
|
136
|
|
136
|
|
137
|
// activity/image state
|
137
|
// activity/image state
|
138
|
//
|
138
|
//
|
|
@@ -145,28 +145,28 @@ typedef enum { |
|
@@ -145,28 +145,28 @@ typedef enum { |
145
|
options:UIViewAnimationOptionBeginFromCurrentState
|
145
|
options:UIViewAnimationOptionBeginFromCurrentState
|
146
|
animations:^(void)
|
146
|
animations:^(void)
|
147
|
{
|
147
|
{
|
148
|
- buttonImageView.transform = CGAffineTransformMakeScale(0.01, 0.01);
|
|
|
149
|
- activityView.transform = CGAffineTransformMakeScale(0.01, 0.01);
|
148
|
+ _buttonImageView.transform = CGAffineTransformMakeScale(0.01, 0.01);
|
|
|
149
|
+ _activityView.transform = CGAffineTransformMakeScale(0.01, 0.01);
|
150
|
}
|
150
|
}
|
151
|
completion:^(BOOL finished)
|
151
|
completion:^(BOOL finished)
|
152
|
{
|
152
|
{
|
153
|
- buttonImageView.hidden = YES;
|
153
|
+ _buttonImageView.hidden = YES;
|
154
|
|
154
|
|
155
|
- [activityView startAnimating];
|
155
|
+ [_activityView startAnimating];
|
156
|
|
156
|
|
157
|
[UIView animateWithDuration:0.25 animations:^(void)
|
157
|
[UIView animateWithDuration:0.25 animations:^(void)
|
158
|
{
|
158
|
{
|
159
|
- buttonImageView.transform = CGAffineTransformIdentity;
|
|
|
160
|
- activityView.transform = CGAffineTransformIdentity;
|
159
|
+ _buttonImageView.transform = CGAffineTransformIdentity;
|
|
|
160
|
+ _activityView.transform = CGAffineTransformIdentity;
|
161
|
}];
|
161
|
}];
|
162
|
}];
|
162
|
}];
|
163
|
|
163
|
|
164
|
- state = RMUserTrackingButtonStateActivity;
|
164
|
+ _state = RMUserTrackingButtonStateActivity;
|
165
|
}
|
165
|
}
|
166
|
else
|
166
|
else
|
167
|
{
|
167
|
{
|
168
|
- if ((_mapView.userTrackingMode != RMUserTrackingModeFollowWithHeading && state != RMUserTrackingButtonStateLocation) ||
|
|
|
169
|
- (_mapView.userTrackingMode == RMUserTrackingModeFollowWithHeading && state != RMUserTrackingButtonStateHeading))
|
168
|
+ if ((_mapView.userTrackingMode != RMUserTrackingModeFollowWithHeading && _state != RMUserTrackingButtonStateLocation) ||
|
|
|
169
|
+ (_mapView.userTrackingMode == RMUserTrackingModeFollowWithHeading && _state != RMUserTrackingButtonStateHeading))
|
170
|
{
|
170
|
{
|
171
|
// if image state doesn't match mode, update it
|
171
|
// if image state doesn't match mode, update it
|
172
|
//
|
172
|
//
|
|
@@ -175,24 +175,24 @@ typedef enum { |
|
@@ -175,24 +175,24 @@ typedef enum { |
175
|
options:UIViewAnimationOptionBeginFromCurrentState
|
175
|
options:UIViewAnimationOptionBeginFromCurrentState
|
176
|
animations:^(void)
|
176
|
animations:^(void)
|
177
|
{
|
177
|
{
|
178
|
- buttonImageView.transform = CGAffineTransformMakeScale(0.01, 0.01);
|
|
|
179
|
- activityView.transform = CGAffineTransformMakeScale(0.01, 0.01);
|
178
|
+ _buttonImageView.transform = CGAffineTransformMakeScale(0.01, 0.01);
|
|
|
179
|
+ _activityView.transform = CGAffineTransformMakeScale(0.01, 0.01);
|
180
|
}
|
180
|
}
|
181
|
completion:^(BOOL finished)
|
181
|
completion:^(BOOL finished)
|
182
|
{
|
182
|
{
|
183
|
- buttonImageView.image = [UIImage imageNamed:(_mapView.userTrackingMode == RMUserTrackingModeFollowWithHeading ? @"TrackingHeading.png" : @"TrackingLocation.png")];
|
|
|
184
|
- buttonImageView.hidden = NO;
|
183
|
+ _buttonImageView.image = [UIImage imageNamed:(_mapView.userTrackingMode == RMUserTrackingModeFollowWithHeading ? @"TrackingHeading.png" : @"TrackingLocation.png")];
|
|
|
184
|
+ _buttonImageView.hidden = NO;
|
185
|
|
185
|
|
186
|
- [activityView stopAnimating];
|
186
|
+ [_activityView stopAnimating];
|
187
|
|
187
|
|
188
|
[UIView animateWithDuration:0.25 animations:^(void)
|
188
|
[UIView animateWithDuration:0.25 animations:^(void)
|
189
|
{
|
189
|
{
|
190
|
- buttonImageView.transform = CGAffineTransformIdentity;
|
|
|
191
|
- activityView.transform = CGAffineTransformIdentity;
|
190
|
+ _buttonImageView.transform = CGAffineTransformIdentity;
|
|
|
191
|
+ _activityView.transform = CGAffineTransformIdentity;
|
192
|
}];
|
192
|
}];
|
193
|
}];
|
193
|
}];
|
194
|
|
194
|
|
195
|
- state = (_mapView.userTrackingMode == RMUserTrackingModeFollowWithHeading ? RMUserTrackingButtonStateHeading : RMUserTrackingButtonStateLocation);
|
195
|
+ _state = (_mapView.userTrackingMode == RMUserTrackingModeFollowWithHeading ? RMUserTrackingButtonStateHeading : RMUserTrackingButtonStateLocation);
|
196
|
}
|
196
|
}
|
197
|
}
|
197
|
}
|
198
|
}
|
198
|
}
|