...
|
...
|
@@ -34,39 +34,39 @@ typedef enum { |
|
|
@implementation RMUserTrackingBarButtonItem
|
|
|
|
|
|
@synthesize mapView = _mapView;
|
|
|
@synthesize segmentedControl;
|
|
|
@synthesize buttonImageView;
|
|
|
@synthesize activityView;
|
|
|
@synthesize state;
|
|
|
@synthesize segmentedControl = _segmentedControl;
|
|
|
@synthesize buttonImageView = _buttonImageView;
|
|
|
@synthesize activityView = _activityView;
|
|
|
@synthesize state = _state;
|
|
|
|
|
|
- (id)initWithMapView:(RMMapView *)mapView
|
|
|
{
|
|
|
if ( ! (self = [super initWithCustomView:[[UIControl alloc] initWithFrame:CGRectMake(0, 0, 32, 32)]]))
|
|
|
return nil;
|
|
|
|
|
|
segmentedControl = [[[UISegmentedControl alloc] initWithItems:[NSArray arrayWithObject:@""]] retain];
|
|
|
segmentedControl.segmentedControlStyle = UISegmentedControlStyleBar;
|
|
|
[segmentedControl setWidth:32.0 forSegmentAtIndex:0];
|
|
|
segmentedControl.userInteractionEnabled = NO;
|
|
|
segmentedControl.tintColor = self.tintColor;
|
|
|
segmentedControl.center = self.customView.center;
|
|
|
_segmentedControl = [[[UISegmentedControl alloc] initWithItems:[NSArray arrayWithObject:@""]] retain];
|
|
|
_segmentedControl.segmentedControlStyle = UISegmentedControlStyleBar;
|
|
|
[_segmentedControl setWidth:32.0 forSegmentAtIndex:0];
|
|
|
_segmentedControl.userInteractionEnabled = NO;
|
|
|
_segmentedControl.tintColor = self.tintColor;
|
|
|
_segmentedControl.center = self.customView.center;
|
|
|
|
|
|
[self.customView addSubview:segmentedControl];
|
|
|
[self.customView addSubview:_segmentedControl];
|
|
|
|
|
|
buttonImageView = [[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"TrackingLocation.png"]] retain];
|
|
|
buttonImageView.contentMode = UIViewContentModeCenter;
|
|
|
buttonImageView.frame = CGRectMake(0, 0, 32, 32);
|
|
|
buttonImageView.center = self.customView.center;
|
|
|
buttonImageView.userInteractionEnabled = NO;
|
|
|
_buttonImageView = [[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"TrackingLocation.png"]] retain];
|
|
|
_buttonImageView.contentMode = UIViewContentModeCenter;
|
|
|
_buttonImageView.frame = CGRectMake(0, 0, 32, 32);
|
|
|
_buttonImageView.center = self.customView.center;
|
|
|
_buttonImageView.userInteractionEnabled = NO;
|
|
|
|
|
|
[self.customView addSubview:buttonImageView];
|
|
|
[self.customView addSubview:_buttonImageView];
|
|
|
|
|
|
activityView = [[[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite] retain];
|
|
|
activityView.hidesWhenStopped = YES;
|
|
|
activityView.center = self.customView.center;
|
|
|
activityView.userInteractionEnabled = NO;
|
|
|
_activityView = [[[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite] retain];
|
|
|
_activityView.hidesWhenStopped = YES;
|
|
|
_activityView.center = self.customView.center;
|
|
|
_activityView.userInteractionEnabled = NO;
|
|
|
|
|
|
[self.customView addSubview:activityView];
|
|
|
[self.customView addSubview:_activityView];
|
|
|
|
|
|
[((UIControl *)self.customView) addTarget:self action:@selector(changeMode:) forControlEvents:UIControlEventTouchUpInside];
|
|
|
|
...
|
...
|
@@ -75,7 +75,7 @@ typedef enum { |
|
|
[_mapView addObserver:self forKeyPath:@"userTrackingMode" options:NSKeyValueObservingOptionNew context:nil];
|
|
|
[_mapView addObserver:self forKeyPath:@"userLocation.location" options:NSKeyValueObservingOptionNew context:nil];
|
|
|
|
|
|
state = RMUserTrackingButtonStateLocation;
|
|
|
_state = RMUserTrackingButtonStateLocation;
|
|
|
|
|
|
[self updateAppearance];
|
|
|
|
...
|
...
|
@@ -84,9 +84,9 @@ typedef enum { |
|
|
|
|
|
- (void)dealloc
|
|
|
{
|
|
|
[segmentedControl release]; segmentedControl = nil;
|
|
|
[buttonImageView release]; buttonImageView = nil;
|
|
|
[activityView release]; activityView = nil;
|
|
|
[_segmentedControl release]; _segmentedControl = nil;
|
|
|
[_buttonImageView release]; _buttonImageView = nil;
|
|
|
[_activityView release]; _activityView = nil;
|
|
|
[_mapView removeObserver:self forKeyPath:@"userTrackingMode"];
|
|
|
[_mapView removeObserver:self forKeyPath:@"userLocation.location"];
|
|
|
[_mapView release]; _mapView = nil;
|
...
|
...
|
@@ -116,7 +116,7 @@ typedef enum { |
|
|
{
|
|
|
[super setTintColor:newTintColor];
|
|
|
|
|
|
segmentedControl.tintColor = newTintColor;
|
|
|
_segmentedControl.tintColor = newTintColor;
|
|
|
}
|
|
|
|
|
|
#pragma mark -
|
...
|
...
|
@@ -132,7 +132,7 @@ typedef enum { |
|
|
{
|
|
|
// "selection" state
|
|
|
//
|
|
|
segmentedControl.selectedSegmentIndex = (_mapView.userTrackingMode == RMUserTrackingModeNone ? UISegmentedControlNoSegment : 0);
|
|
|
_segmentedControl.selectedSegmentIndex = (_mapView.userTrackingMode == RMUserTrackingModeNone ? UISegmentedControlNoSegment : 0);
|
|
|
|
|
|
// activity/image state
|
|
|
//
|
...
|
...
|
@@ -145,28 +145,28 @@ typedef enum { |
|
|
options:UIViewAnimationOptionBeginFromCurrentState
|
|
|
animations:^(void)
|
|
|
{
|
|
|
buttonImageView.transform = CGAffineTransformMakeScale(0.01, 0.01);
|
|
|
activityView.transform = CGAffineTransformMakeScale(0.01, 0.01);
|
|
|
_buttonImageView.transform = CGAffineTransformMakeScale(0.01, 0.01);
|
|
|
_activityView.transform = CGAffineTransformMakeScale(0.01, 0.01);
|
|
|
}
|
|
|
completion:^(BOOL finished)
|
|
|
{
|
|
|
buttonImageView.hidden = YES;
|
|
|
_buttonImageView.hidden = YES;
|
|
|
|
|
|
[activityView startAnimating];
|
|
|
[_activityView startAnimating];
|
|
|
|
|
|
[UIView animateWithDuration:0.25 animations:^(void)
|
|
|
{
|
|
|
buttonImageView.transform = CGAffineTransformIdentity;
|
|
|
activityView.transform = CGAffineTransformIdentity;
|
|
|
_buttonImageView.transform = CGAffineTransformIdentity;
|
|
|
_activityView.transform = CGAffineTransformIdentity;
|
|
|
}];
|
|
|
}];
|
|
|
|
|
|
state = RMUserTrackingButtonStateActivity;
|
|
|
_state = RMUserTrackingButtonStateActivity;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
if ((_mapView.userTrackingMode != RMUserTrackingModeFollowWithHeading && state != RMUserTrackingButtonStateLocation) ||
|
|
|
(_mapView.userTrackingMode == RMUserTrackingModeFollowWithHeading && state != RMUserTrackingButtonStateHeading))
|
|
|
if ((_mapView.userTrackingMode != RMUserTrackingModeFollowWithHeading && _state != RMUserTrackingButtonStateLocation) ||
|
|
|
(_mapView.userTrackingMode == RMUserTrackingModeFollowWithHeading && _state != RMUserTrackingButtonStateHeading))
|
|
|
{
|
|
|
// if image state doesn't match mode, update it
|
|
|
//
|
...
|
...
|
@@ -175,24 +175,24 @@ typedef enum { |
|
|
options:UIViewAnimationOptionBeginFromCurrentState
|
|
|
animations:^(void)
|
|
|
{
|
|
|
buttonImageView.transform = CGAffineTransformMakeScale(0.01, 0.01);
|
|
|
activityView.transform = CGAffineTransformMakeScale(0.01, 0.01);
|
|
|
_buttonImageView.transform = CGAffineTransformMakeScale(0.01, 0.01);
|
|
|
_activityView.transform = CGAffineTransformMakeScale(0.01, 0.01);
|
|
|
}
|
|
|
completion:^(BOOL finished)
|
|
|
{
|
|
|
buttonImageView.image = [UIImage imageNamed:(_mapView.userTrackingMode == RMUserTrackingModeFollowWithHeading ? @"TrackingHeading.png" : @"TrackingLocation.png")];
|
|
|
buttonImageView.hidden = NO;
|
|
|
_buttonImageView.image = [UIImage imageNamed:(_mapView.userTrackingMode == RMUserTrackingModeFollowWithHeading ? @"TrackingHeading.png" : @"TrackingLocation.png")];
|
|
|
_buttonImageView.hidden = NO;
|
|
|
|
|
|
[activityView stopAnimating];
|
|
|
[_activityView stopAnimating];
|
|
|
|
|
|
[UIView animateWithDuration:0.25 animations:^(void)
|
|
|
{
|
|
|
buttonImageView.transform = CGAffineTransformIdentity;
|
|
|
activityView.transform = CGAffineTransformIdentity;
|
|
|
_buttonImageView.transform = CGAffineTransformIdentity;
|
|
|
_activityView.transform = CGAffineTransformIdentity;
|
|
|
}];
|
|
|
}];
|
|
|
|
|
|
state = (_mapView.userTrackingMode == RMUserTrackingModeFollowWithHeading ? RMUserTrackingButtonStateHeading : RMUserTrackingButtonStateLocation);
|
|
|
_state = (_mapView.userTrackingMode == RMUserTrackingModeFollowWithHeading ? RMUserTrackingButtonStateHeading : RMUserTrackingButtonStateLocation);
|
|
|
}
|
|
|
}
|
|
|
}
|
...
|
...
|
|