summaryrefslogtreecommitdiff
path: root/platform
diff options
context:
space:
mode:
authorMinh Nguyễn <mxn@1ec5.org>2016-01-18 17:45:38 -0800
committerMinh Nguyễn <mxn@1ec5.org>2016-01-20 11:02:31 -0800
commit65f6eb25b5a0ef4e6feb712faceb71a44779f54f (patch)
tree069a81fddb2eeea111f602ff26090c06659acd77 /platform
parent07c4c541112d1b5cc74ee4b1e636bfc7501db6ae (diff)
downloadqtlocation-mapboxgl-65f6eb25b5a0ef4e6feb712faceb71a44779f54f.tar.gz
[ios, osx] Optionally animate content insets change
Diffstat (limited to 'platform')
-rw-r--r--platform/ios/src/MGLMapView.mm39
-rw-r--r--platform/osx/src/MGLMapView.mm24
2 files changed, 43 insertions, 20 deletions
diff --git a/platform/ios/src/MGLMapView.mm b/platform/ios/src/MGLMapView.mm
index 93b30cb177..d1639f4583 100644
--- a/platform/ios/src/MGLMapView.mm
+++ b/platform/ios/src/MGLMapView.mm
@@ -810,24 +810,37 @@ std::chrono::steady_clock::duration MGLDurationInSeconds(float duration)
return;
}
- UIEdgeInsets contentInsets = UIEdgeInsetsZero;
+ UIEdgeInsets contentInset = UIEdgeInsetsZero;
CGPoint topPoint = CGPointMake(0, viewController.topLayoutGuide.length);
- contentInsets.top = [self convertPoint:topPoint fromView:viewController.view].y;
+ contentInset.top = [self convertPoint:topPoint fromView:viewController.view].y;
CGPoint bottomPoint = CGPointMake(0, CGRectGetMaxY(viewController.view.bounds)
- viewController.bottomLayoutGuide.length);
- contentInsets.bottom = (CGRectGetMaxY(self.bounds) - [self convertPoint:bottomPoint
- fromView:viewController.view].y);
-
- if ( ! UIEdgeInsetsEqualToEdgeInsets(contentInsets, self.contentInset))
+ contentInset.bottom = (CGRectGetMaxY(self.bounds)
+ - [self convertPoint:bottomPoint fromView:viewController.view].y);
+ self.contentInset = contentInset;
+}
+
+- (void)setContentInset:(UIEdgeInsets)contentInset
+{
+ [self setContentInset:contentInset animated:NO];
+}
+
+- (void)setContentInset:(UIEdgeInsets)contentInset animated:(BOOL)animated
+{
+ if (UIEdgeInsetsEqualToEdgeInsets(contentInset, self.contentInset))
{
- // After adjusting the content insets, move the center coordinate from
- // the old frame of reference to the new one represented by the newly
- // set content insets.
- CLLocationCoordinate2D oldCenter = self.centerCoordinate;
- self.contentInset = contentInsets;
- // Don’t call -setCenterCoordinate:, which resets the user tracking mode.
- [self _setCenterCoordinate:oldCenter animated:NO];
+ return;
}
+
+ // After adjusting the content inset, move the center coordinate from the
+ // old frame of reference to the new one represented by the newly set
+ // content inset.
+ CLLocationCoordinate2D oldCenter = self.centerCoordinate;
+
+ _contentInset = contentInset;
+
+ // Don’t call -setCenterCoordinate:, which resets the user tracking mode.
+ [self _setCenterCoordinate:oldCenter animated:animated];
}
/// Returns the frame of inset content within the map view.
diff --git a/platform/osx/src/MGLMapView.mm b/platform/osx/src/MGLMapView.mm
index 9c32e7204d..e1c472409e 100644
--- a/platform/osx/src/MGLMapView.mm
+++ b/platform/osx/src/MGLMapView.mm
@@ -1117,14 +1117,24 @@ public:
contentInsets = NSEdgeInsetsZero;
}
- if (!NSEdgeInsetsEqual(contentInsets, self.contentInsets)) {
- // After adjusting the content insets, move the center coordinate from
- // the old frame of reference to the new one represented by the newly
- // set content insets.
- CLLocationCoordinate2D oldCenter = self.centerCoordinate;
- self.contentInsets = contentInsets;
- self.centerCoordinate = oldCenter;
+ self.contentInsets = contentInsets;
+}
+
+- (void)setContentInsets:(NSEdgeInsets)contentInsets {
+ [self setContentInsets:contentInsets animated:NO];
+}
+
+- (void)setContentInsets:(NSEdgeInsets)contentInsets animated:(BOOL)animated {
+ if (NSEdgeInsetsEqual(contentInsets, self.contentInsets)) {
+ return;
}
+
+ // After adjusting the content insets, move the center coordinate from the
+ // old frame of reference to the new one represented by the newly set
+ // content insets.
+ CLLocationCoordinate2D oldCenter = self.centerCoordinate;
+ _contentInsets = contentInsets;
+ [self setCenterCoordinate:oldCenter animated:animated];
}
#pragma mark Mouse events and gestures