diff --git a/platform/ios/app/MBXViewController.m b/platform/ios/app/MBXViewController.m index 39458c4f31c..606a0ac61b5 100644 --- a/platform/ios/app/MBXViewController.m +++ b/platform/ios/app/MBXViewController.m @@ -156,7 +156,7 @@ - (void)viewDidLoad [self restoreState:nil]; self.debugLoggingEnabled = [[NSUserDefaults standardUserDefaults] boolForKey:@"MGLMapboxMetricsDebugLoggingEnabled"]; - + self.mapView.scaleBar.hidden = NO; self.hudLabel.hidden = YES; if ([MGLAccountManager accessToken].length) diff --git a/platform/ios/src/MGLMapView.h b/platform/ios/src/MGLMapView.h index 785484520e0..62f6d9812a8 100644 --- a/platform/ios/src/MGLMapView.h +++ b/platform/ios/src/MGLMapView.h @@ -226,11 +226,8 @@ IB_DESIGNABLE - (IBAction)reloadStyle:(id)sender; /** - A control indicating the scale of the map. - - The scale bar becomes visible when a user interacts with the map and fades out - when the interaction stops. The scale bar is positioned in the upper-left - corner. + A control indicating the scale of the map. The scale bar is positioned in the + upper-left corner. */ @property (nonatomic, readonly) UIView *scaleBar; diff --git a/platform/ios/src/MGLMapView.mm b/platform/ios/src/MGLMapView.mm index 587cd283345..20c371b5f51 100644 --- a/platform/ios/src/MGLMapView.mm +++ b/platform/ios/src/MGLMapView.mm @@ -1274,7 +1274,6 @@ - (void)handlePanGesture:(UIPanGestureRecognizer *)pan } [self notifyGestureDidEndWithDrift:drift]; - [self notifyScaleBarGestureDidEnd]; // metrics: pan end CGPoint pointInView = CGPointMake([pan locationInView:pan.view].x, [pan locationInView:pan.view].y); @@ -1385,7 +1384,6 @@ - (void)handlePinchGesture:(UIPinchGestureRecognizer *)pinch [self notifyGestureDidEndWithDrift:drift]; [self unrotateIfNeededForGesture]; - [self notifyScaleBarGestureDidEnd]; } _previousPinchCenterCoordinate = [self convertPoint:centerPoint toCoordinateFromView:self]; @@ -1466,7 +1464,6 @@ - (void)handleRotateGesture:(UIRotationGestureRecognizer *)rotate else { [self notifyGestureDidEndWithDrift:NO]; - [self notifyScaleBarGestureDidEnd]; [self unrotateIfNeededForGesture]; } } @@ -1604,11 +1601,9 @@ - (void)handleDoubleTapGesture:(UITapGestureRecognizer *)doubleTap [self animateWithDelay:MGLAnimationDuration animations:^ { [weakSelf unrotateIfNeededForGesture]; - [weakSelf notifyScaleBarGestureDidEnd]; }]; } else { [self unrotateIfNeededForGesture]; - [self notifyScaleBarGestureDidEnd]; } } } @@ -1646,7 +1641,6 @@ - (void)handleTwoFingerTapGesture:(UITapGestureRecognizer *)twoFingerTap [self animateWithDelay:MGLAnimationDuration animations:^ { [weakSelf unrotateIfNeededForGesture]; - [weakSelf notifyScaleBarGestureDidEnd]; }]; } } @@ -1698,7 +1692,6 @@ - (void)handleQuickZoomGesture:(UILongPressGestureRecognizer *)quickZoom else if (quickZoom.state == UIGestureRecognizerStateEnded || quickZoom.state == UIGestureRecognizerStateCancelled) { [self notifyGestureDidEndWithDrift:NO]; - [self notifyScaleBarGestureDidEnd]; [self unrotateIfNeededForGesture]; } } @@ -1738,7 +1731,6 @@ - (void)handleTwoFingerDragGesture:(UIPanGestureRecognizer *)twoFingerDrag else if (twoFingerDrag.state == UIGestureRecognizerStateEnded || twoFingerDrag.state == UIGestureRecognizerStateCancelled) { [self notifyGestureDidEndWithDrift:NO]; - [self notifyScaleBarGestureDidEnd]; [self unrotateIfNeededForGesture]; } @@ -5205,11 +5197,6 @@ - (CGPoint)userLocationAnnotationViewCenter return center; } -- (void)notifyScaleBarGestureDidEnd -{ - [(MGLScaleBar *)self.scaleBar fadeOut]; -} - - (void)updateCompass { CLLocationDirection direction = self.direction; diff --git a/platform/ios/src/MGLScaleBar.h b/platform/ios/src/MGLScaleBar.h index 85bb1655453..77fd6736b58 100644 --- a/platform/ios/src/MGLScaleBar.h +++ b/platform/ios/src/MGLScaleBar.h @@ -3,10 +3,7 @@ @interface MGLScaleBar : UIView -// Sets the scale and fades in the scale bar +// Sets the scale and redraws the scale bar @property (nonatomic, assign) CLLocationDistance metersPerPoint; -// Fades out the scale bar -- (void)fadeOut; - @end diff --git a/platform/ios/src/MGLScaleBar.mm b/platform/ios/src/MGLScaleBar.mm index 703067f133c..f6490cf4fef 100644 --- a/platform/ios/src/MGLScaleBar.mm +++ b/platform/ios/src/MGLScaleBar.mm @@ -36,12 +36,6 @@ {.distance = 500000, .numberOfBars = 2}, {.distance = 600000, .numberOfBars = 3}, {.distance = 800000, .numberOfBars = 2}, - {.distance = 1000000, .numberOfBars = 2}, - {.distance = 1200000, .numberOfBars = 2}, - {.distance = 1600000, .numberOfBars = 2}, - {.distance = 2000000, .numberOfBars = 2}, - {.distance = 3500000, .numberOfBars = 2}, - {.distance = 5000000, .numberOfBars = 2}, }; static const MGLRow MGLImperialTable[] ={ @@ -76,17 +70,11 @@ {.distance = 200*MGLFeetPerMile, .numberOfBars = 2}, {.distance = 300*MGLFeetPerMile, .numberOfBars = 3}, {.distance = 400*MGLFeetPerMile, .numberOfBars = 2}, - {.distance = 800*MGLFeetPerMile, .numberOfBars = 2}, - {.distance = 1000*MGLFeetPerMile, .numberOfBars = 2}, - {.distance = 2000*MGLFeetPerMile, .numberOfBars = 2}, - {.distance = 3000*MGLFeetPerMile, .numberOfBars = 3}, - {.distance = 4000*MGLFeetPerMile, .numberOfBars = 2}, }; @class MGLScaleBarLabel; @interface MGLScaleBar() -@property (nonatomic, assign, getter=isVisible) BOOL visible; @property (nonatomic) NSArray *labels; @property (nonatomic) NSArray *bars; @property (nonatomic) UIView *containerView; @@ -145,13 +133,12 @@ - (instancetype)initWithFrame:(CGRect)frame { } - (void)commonInit { - _visible = NO; _primaryColor = [UIColor colorWithRed:18.0/255.0 green:45.0/255.0 blue:17.0/255.0 alpha:1]; _secondaryColor = [UIColor colorWithRed:247.0/255.0 green:247.0/255.0 blue:247.0/255.0 alpha:1]; _borderWidth = 1.0f; self.clipsToBounds = NO; - self.alpha = 0; + self.hidden = YES; _containerView = [[UIView alloc] init]; _containerView.clipsToBounds = YES; @@ -219,30 +206,6 @@ - (MGLRow)preferredRow { return row; } -- (void)fadeIn { - if (self.isVisible) { - return; - } - - self.visible = YES; - - [UIView animateWithDuration:.2 delay:0 options:UIViewAnimationOptionBeginFromCurrentState animations:^{ - self.alpha = 1.0; - } completion:nil]; -} - -- (void)fadeOut { - if (!self.isVisible) { - return; - } - - self.visible = NO; - - [UIView animateWithDuration:.3 delay:0.7 options:UIViewAnimationOptionBeginFromCurrentState animations:^{ - self.alpha = 0.0; - } completion:nil]; -} - #pragma mark - Setters - (void)setMetersPerPoint:(CLLocationDistance)metersPerPoint { @@ -250,16 +213,31 @@ - (void)setMetersPerPoint:(CLLocationDistance)metersPerPoint { return; } - [self fadeIn]; - _metersPerPoint = metersPerPoint; + [self updateVisibility]; + self.row = [self preferredRow]; [self invalidateIntrinsicContentSize]; [self setNeedsLayout]; } +- (void)updateVisibility { + BOOL metric = [self usesMetricSystem]; + + NSUInteger count = metric + ? sizeof(MGLMetricTable) / sizeof(MGLMetricTable[0]) + : sizeof(MGLImperialTable) / sizeof(MGLImperialTable[0]); + + CLLocationDistance maximumDistance = [self maximumWidth] * [self unitsPerPoint]; + CLLocationDistance allowedDistance = metric + ? MGLMetricTable[count-1].distance + : MGLImperialTable[count-1].distance; + + self.alpha = maximumDistance > allowedDistance ? 0 : 1; +} + - (void)setRow:(MGLRow)row { if (_row.distance == row.distance) { return;