summaryrefslogtreecommitdiff
path: root/platform/ios/app
diff options
context:
space:
mode:
authorMinh Nguyễn <mxn@1ec5.org>2016-06-05 13:29:23 -0700
committerMinh Nguyễn <mxn@1ec5.org>2016-07-02 21:00:41 -0700
commitbb2f627b1287483749487e405931d3cbe2c5363e (patch)
tree27d1e359f8bc289532810a28b92d3240b13a6216 /platform/ios/app
parentbb4606b53de1ae06cff81d7f05be31d163b78f86 (diff)
downloadqtlocation-mapboxgl-bb2f627b1287483749487e405931d3cbe2c5363e.tar.gz
[ios] Made annotation view position animatable
We don’t normally want an annotation view to animate its position, because that makes the view appear to lag behind the map. But when the annotation view moves due to the underlying annotation model object moving, the developer may want exactly that effect. This change continues to disable the default implicit bounds (and now position) animation. It also groups the view updates in -updateAnnotationViews in a transaction that disables animation actions, to improve perceived performance with a large number of annotations. However, when the annotation model object changes, we move the annotation view outside of that transaction to allow the developer to opt into animation. If the developer moreover wants the annotation view to animate even due to the viewport changing, they can override -setCenter: to use a UIView animation block. Fixes #5230.
Diffstat (limited to 'platform/ios/app')
-rw-r--r--platform/ios/app/MBXAnnotationView.m13
1 files changed, 13 insertions, 0 deletions
diff --git a/platform/ios/app/MBXAnnotationView.m b/platform/ios/app/MBXAnnotationView.m
index c181211431..82af15314a 100644
--- a/platform/ios/app/MBXAnnotationView.m
+++ b/platform/ios/app/MBXAnnotationView.m
@@ -51,6 +51,7 @@
case MGLAnnotationViewDragStateCanceling:
break;
case MGLAnnotationViewDragStateEnding: {
+ self.transform = CGAffineTransformScale(CGAffineTransformIdentity, 2, 2);
[UIView animateWithDuration:.4 delay:0 usingSpringWithDamping:.4 initialSpringVelocity:.5 options:UIViewAnimationOptionCurveLinear animations:^{
self.transform = CGAffineTransformScale(CGAffineTransformIdentity, 1, 1);
} completion:nil];
@@ -60,5 +61,17 @@
}
+- (nullable id<CAAction>)actionForLayer:(CALayer *)layer forKey:(NSString *)event
+{
+ if (([event isEqualToString:@"transform"] || [event isEqualToString:@"position"])
+ && self.dragState == MGLAnnotationViewDragStateNone)
+ {
+ CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:event];
+ animation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
+ animation.speed = 0.1;
+ return animation;
+ }
+ return [super actionForLayer:layer forKey:event];
+}
@end