我可以动画添加 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
突然变为 nil 并annotation.layer
从地图中删除。所以没有动画发生!
- (void)mapView:(RMMapView *)mapView willHideLayerForAnnotation:(RMAnnotation *)annotation
你有什么想法?我应该如何为删除的 RMAnnotation 对象设置动画?