diff options
Diffstat (limited to 'platform/ios/app/MBXViewController.m')
-rw-r--r-- | platform/ios/app/MBXViewController.m | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/platform/ios/app/MBXViewController.m b/platform/ios/app/MBXViewController.m index 2fb95e1b17..4f6d7987a6 100644 --- a/platform/ios/app/MBXViewController.m +++ b/platform/ios/app/MBXViewController.m @@ -215,6 +215,7 @@ CLLocationCoordinate2D randomWorldCoordinate() { @property (nonatomic) NSMutableArray<UIWindow *> *helperWindows; @property (nonatomic) NSMutableArray<UIView *> *contentInsetsOverlays; +@property (nonatomic) NSTimer *hideScaleBarTimer; @end @interface MGLMapView (MBXViewController) @@ -302,6 +303,41 @@ CLLocationCoordinate2D randomWorldCoordinate() { } } }]; + + [self handleZoomOnScale]; +} + +- (void)viewWillDisappear:(BOOL)animated { + [self hideScaleWithAnimation:NO]; +} +- (void)handleZoomOnScale { + if (!self.mapView.showsScale) { return; } + + self.mapView.scaleBar.alpha = 1; + + if (self.hideScaleBarTimer) { + [self.hideScaleBarTimer invalidate]; + } + + __weak typeof(self) weakSelf = self; + self.hideScaleBarTimer = [NSTimer scheduledTimerWithTimeInterval:2.0 repeats:NO block:^(NSTimer * _Nonnull timer) { + if (![timer isValid]) { + [weakSelf hideScaleWithAnimation:YES]; + } + }]; +} + +- (void)hideScaleWithAnimation:(BOOL)animated { + [self.hideScaleBarTimer invalidate]; + self.hideScaleBarTimer = nil; + + if (!animated) { return; } + __weak typeof(self) weakSelf = self; + [UIView animateWithDuration:0.3 delay:0 options:UIViewAnimationOptionBeginFromCurrentState animations:^{ + self.mapView.scaleBar.alpha = 0; + } completion:^(BOOL finished) { + weakSelf.mapView.showsScale = NO; + }]; } - (UIInterfaceOrientationMask)supportedInterfaceOrientations |