Skip to content
This repository was archived by the owner on Aug 8, 2023. It is now read-only.

[ios] added check for annotation view animation #8565

Merged
merged 2 commits into from
Apr 12, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 0 additions & 13 deletions platform/ios/app/MBXAnnotationView.m
Original file line number Diff line number Diff line change
Expand Up @@ -49,17 +49,4 @@ - (void)setDragState:(MGLAnnotationViewDragState)dragState animated:(BOOL)animat

}

- (nullable id<CAAction>)actionForLayer:(CALayer *)layer forKey:(NSString *)event
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just noting that I think removing this makes sense only because I also think that we should feature UIView animation blocks as the recommended way of performing annotation view animations. Animation blocks have the convenient side effect of animating any open callout view along with the annotation view. cc @1ec5

{
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
22 changes: 22 additions & 0 deletions platform/ios/app/MBXViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ typedef NS_ENUM(NSInteger, MBXSettingsAnnotationsRows) {
MBXSettingsAnnotations100Sprites,
MBXSettingsAnnotations1000Sprites,
MBXSettingsAnnotations10000Sprites,
MBXSettingsAnnotationAnimation,
MBXSettingsAnnotationsTestShapes,
MBXSettingsAnnotationsCustomCallout,
MBXSettingsAnnotationsQueryAnnotations,
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -713,6 +718,23 @@ - (void)parseFeaturesAddingCount:(NSUInteger)featuresCount usingViews:(BOOL)useV
});
}

- (void)animateAnnotationView
{
MGLPointAnnotation *annot = [[MGLPointAnnotation alloc] init];
annot.coordinate = self.mapView.centerCoordinate;
[self.mapView addAnnotation:annot];

// 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(), ^{
[UIView animateWithDuration:10 animations:^{
annot.coordinate = coord;
}];
});
};

- (void)addTestShapes
{
// Pacific Northwest triangle
Expand Down
3 changes: 3 additions & 0 deletions platform/ios/src/MGLMapView.mm
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down