From 0d1ab526b7bc1322ec5fd61e90e529d4f29ef387 Mon Sep 17 00:00:00 2001 From: jmkiley Date: Tue, 28 Mar 2017 18:47:22 -0700 Subject: [PATCH 1/2] [ios] added guard for animations, example --- platform/ios/app/MBXAnnotationView.m | 13 ------------- platform/ios/app/MBXViewController.m | 21 +++++++++++++++++++++ platform/ios/src/MGLMapView.mm | 3 +++ 3 files changed, 24 insertions(+), 13 deletions(-) diff --git a/platform/ios/app/MBXAnnotationView.m b/platform/ios/app/MBXAnnotationView.m index 5b8011c55e6..6877c5cd3d5 100644 --- a/platform/ios/app/MBXAnnotationView.m +++ b/platform/ios/app/MBXAnnotationView.m @@ -49,17 +49,4 @@ - (void)setDragState:(MGLAnnotationViewDragState)dragState animated:(BOOL)animat } -- (nullable id)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 diff --git a/platform/ios/app/MBXViewController.m b/platform/ios/app/MBXViewController.m index 7aeb2042dfe..8e1354d524c 100644 --- a/platform/ios/app/MBXViewController.m +++ b/platform/ios/app/MBXViewController.m @@ -44,6 +44,7 @@ typedef NS_ENUM(NSInteger, MBXSettingsAnnotationsRows) { MBXSettingsAnnotations100Sprites, MBXSettingsAnnotations1000Sprites, MBXSettingsAnnotations10000Sprites, + MBXSettingsAnnotationAnimation, MBXSettingsAnnotationsTestShapes, MBXSettingsAnnotationsCustomCallout, MBXSettingsAnnotationsQueryAnnotations, @@ -314,6 +315,7 @@ - (void)dismissSettings:(__unused id)sender @"Add 100 Sprites", @"Add 1,000 Sprites", @"Add 10,000 Sprites", + @"Animate an Annotation View", @"Add Test Shapes", @"Add Point With Custom Callout", @"Query Annotations", @@ -498,6 +500,9 @@ - (void)performActionForSettingAtIndexPath:(NSIndexPath *)indexPath case MBXSettingsAnnotations10000Sprites: [self parseFeaturesAddingCount:10000 usingViews:NO]; break; + case MBXSettingsAnnotationAnimation: + [self animateAnnotationView]; + break; case MBXSettingsAnnotationsTestShapes: [self addTestShapes]; break; @@ -713,6 +718,22 @@ - (void)parseFeaturesAddingCount:(NSUInteger)featuresCount usingViews:(BOOL)useV }); } +- (void)animateAnnotationView + { + MGLPointAnnotation *annot = [[MGLPointAnnotation alloc] init]; + annot.coordinate = self.mapView.centerCoordinate; + [self.mapView addAnnotation:annot]; + + CGPoint point = CGPointMake(-200, CGRectGetMidY(self.view.frame)); + + CLLocationCoordinate2D coord = [self.mapView convertPoint:point toCoordinateFromView:self.view]; + dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ + [UIView animateWithDuration:10 animations:^{ + annot.coordinate = coord; + }]; + }); + }; + - (void)addTestShapes { // Pacific Northwest triangle diff --git a/platform/ios/src/MGLMapView.mm b/platform/ios/src/MGLMapView.mm index 2476ec3e971..b4c9e9d2a74 100644 --- a/platform/ios/src/MGLMapView.mm +++ b/platform/ios/src/MGLMapView.mm @@ -5053,6 +5053,9 @@ - (void)updateAnnotationViews } else { + if (annotationView.layer.animationKeys.count > 0) { + continue; + } CGRect adjustedFrame = annotationView.frame; if (annotationView.layer.presentationLayer) { adjustedFrame.origin.x = -CGRectGetWidth(annotationView.layer.presentationLayer.frame) * 10.0; From 510c212f1b187ded95d0e41c4dce96aa3a5835da Mon Sep 17 00:00:00 2001 From: jmkiley Date: Thu, 30 Mar 2017 13:31:27 -0700 Subject: [PATCH 2/2] [ios] changed example destination point --- platform/ios/app/MBXViewController.m | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/platform/ios/app/MBXViewController.m b/platform/ios/app/MBXViewController.m index 8e1354d524c..a7bab2108ae 100644 --- a/platform/ios/app/MBXViewController.m +++ b/platform/ios/app/MBXViewController.m @@ -724,7 +724,8 @@ - (void)animateAnnotationView annot.coordinate = self.mapView.centerCoordinate; [self.mapView addAnnotation:annot]; - CGPoint point = CGPointMake(-200, CGRectGetMidY(self.view.frame)); + // Move the annotation to a point that is offscreen. + CGPoint point = CGPointMake(self.view.frame.origin.x - 200, CGRectGetMidY(self.view.frame)); CLLocationCoordinate2D coord = [self.mapView convertPoint:point toCoordinateFromView:self.view]; dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{