diff options
author | Jason Wray <jason@mapbox.com> | 2019-07-09 17:59:35 -0700 |
---|---|---|
committer | Jason Wray <jason@mapbox.com> | 2019-07-09 17:59:35 -0700 |
commit | 0f241f1cbe2ae8119f370f2e20c666bf57dbc508 (patch) | |
tree | d4d119bfdb1dd4ca830e77aecd42f0d825bbb8c1 /platform/ios/src/MGLCompassButton.mm | |
parent | 593e8cb210934b0422f77797a4748b7ef1ef1e2b (diff) | |
download | qtlocation-mapboxgl-0f241f1cbe2ae8119f370f2e20c666bf57dbc508.tar.gz |
Add tests and refactor visibility setter
Diffstat (limited to 'platform/ios/src/MGLCompassButton.mm')
-rw-r--r-- | platform/ios/src/MGLCompassButton.mm | 30 |
1 files changed, 21 insertions, 9 deletions
diff --git a/platform/ios/src/MGLCompassButton.mm b/platform/ios/src/MGLCompassButton.mm index 9d0ade4121..94a6820a74 100644 --- a/platform/ios/src/MGLCompassButton.mm +++ b/platform/ios/src/MGLCompassButton.mm @@ -52,6 +52,13 @@ [self sizeToFit]; } +- (void)setCompassVisibility:(MGLOrnamentVisibility)compassVisibility { + if (_compassVisibility == compassVisibility) { return; } + _compassVisibility = compassVisibility; + + [self updateCompassAnimated:NO]; +} + - (UIImage *)compassImage { UIImage *scaleImage = [UIImage mgl_resourceImageNamed:@"Compass"]; UIGraphicsBeginImageContextWithOptions(scaleImage.size, NO, UIScreen.mainScreen.scale); @@ -75,7 +82,12 @@ [self.mapView resetNorth]; } -- (void)updateCompassWithDirection:(CLLocationDirection)direction { +- (void)updateCompass { + [self updateCompassAnimated:YES]; +} + +- (void)updateCompassAnimated:(BOOL)animated { + CLLocationDirection direction = self.mapView.direction; CLLocationDirection plateDirection = mbgl::util::wrap(-direction, 0., 360.); self.transform = CGAffineTransformMakeRotation(MGLRadiansFromDegrees(plateDirection)); @@ -85,26 +97,26 @@ switch (self.compassVisibility) { case MGLOrnamentVisibilityAdaptive: if (direction > 0 && self.alpha < 1) { - [self showCompass]; + [self showCompass:animated]; } else if (direction == 0 && self.alpha > 0) { - [self hideCompass]; + [self hideCompass:animated]; } break; case MGLOrnamentVisibilityVisible: - [self showCompass]; + [self showCompass:animated]; break; case MGLOrnamentVisibilityHidden: - [self hideCompass]; + [self hideCompass:animated]; break; } } -- (void)showCompass { - [self animateToAlpha:1]; +- (void)showCompass:(BOOL)animated { + animated ? [self animateToAlpha:1] : [self setAlpha:1]; } -- (void)hideCompass { - [self animateToAlpha:0]; +- (void)hideCompass:(BOOL)animated { + animated ? [self animateToAlpha:0] : [self setAlpha:0]; } - (void)animateToAlpha:(CGFloat)alpha { |