MapBox动画添加或删除RMAnnotation图层

时间:2015-07-23 09:41:03

标签: ios animation mapbox rmannotation

我可以动画添加RMAnnotation到地图框mapView:

- (RMMapLayer *)mapView:(RMMapView *)mapView layerForAnnotation:(RMAnnotation *)annotation{
//create a new annotation marker
RMMarker *marker = [[RMMarker alloc] initWithUIImage:[UIImage imageNamed:@"pin"]];
marker.anchorPoint = CGPointMake(0.5, 1);

RestaurantAnnotation *restAnnotation = (RestaurantAnnotation *)annotation;
CLLocationCoordinate2D actualCoordinate = restAnnotation.coordinate;
CLLocationCoordinate2D containerCoordinate = restAnnotation.clusterAnnotation.coordinate;

[CATransaction begin];
[CATransaction setAnimationDuration:0.30];
[CATransaction setAnimationTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]];

CABasicAnimation *spreadOutAnimation = [CABasicAnimation animationWithKeyPath:@"position"];

spreadOutAnimation.fromValue = [NSValue valueWithCGPoint:[self.mapView coordinateToPixel:containerCoordinate]];
spreadOutAnimation.toValue   = [NSValue valueWithCGPoint:[self.mapView coordinateToPixel:actualCoordinate]];

[marker addAnimation:spreadOutAnimation forKey:@"spreadOut"];

[CATransaction commit];}

但我在从Mapbox mapView动画中删除了RMAnnotation时遇到了问题。在下面的委托方法中,我尝试动画annotation.layer展开到群集,但annotation.layer突然变为零,annotation.layer从地图中删除。所以没有动画发生!

- (void)mapView:(RMMapView *)mapView willHideLayerForAnnotation:(RMAnnotation *)annotation
你的想法是什么?我该如何为移除的RMAnnotation对象设置动画?

enter image description here

0 个答案:

没有答案