我想动画我正在添加为MKOverLay的圆圈。我希望它从屏幕顶部掉落。如何通过委托方法设置动画?或者它是否添加了叠加层?谁能指出我正确的方向?谢谢!
我在mapView委托方法
中有这个-(MKOverlayView *)mapView:(MKMapView *)mapView viewForOverlay:(id<MKOverlay>)overlay
{
if([overlay isKindOfClass:[MKCircle class]]) {
// Create the view for the radius overlay.
MKCircleView *circleView = [[MKCircleView alloc] initWithOverlay:overlay];
circleView.strokeColor = [UIColor whiteColor];
circleView.fillColor = [[UIColor blueColor] colorWithAlphaComponent:0.2];
return circleView;
}
return nil;
}
我添加了overLays:
MKCircle *circle = [MKCircle circleWithCenterCoordinate:userCoord radius:200];
[mainMapView addOverlay:circle];
答案 0 :(得分:1)
这是一些未经测试的代码。如果确实有效,您可能需要改变动画。
- (void)mapView:(MKMapView *)mapView didAddOverlayViews:(NSArray *)overlayViews
{
for (MKOverlayView *view in overlayViews) {
CGRect endFrame = view.frame;
view.frame = CGRectMake(endFrame.origin.x, endFrame.origin.y-500, 0, 0);
[UIView animateWithDuration:1.0 animations:^{
view.frame = endFrame;
}];
}
}
答案 1 :(得分:1)
假设您希望在动画中放大+淡入淡出,您可以这样做:
@interface MyMapOverlayView : UIView<CAAction>
@end
@implementation MyMapOverlayView
- (id<CAAction>)actionForLayer:(CALayer *)layer forKey:(NSString *)event
{
if ( [ event isEqualToString:@"onOrderIn" ] )
{
return self ;
}
return [ super actionForLayer:layer forKey:event ] ;
}
- (void)runActionForKey:(NSString *)event object:(id)anObject arguments:(NSDictionary *)dict
{
if ( [ event isEqualToString:@"onOrderIn" ] )
{
{
CABasicAnimation * anim = [ CABasicAnimation animationWithKeyPath:@"transform" ] ;
anim.fromValue = [ NSValue valueWithCATransform3D:CATransform3DMakeScale( 0.1f, 0.1f, 1.0f ) ] ;
[ self.layer addAnimation:anim forKey:nil ] ;
}
{
CABasicAnimation * anim = [ CABasicAnimation animationWithKeyPath:@"opacity" ] ;
anim.fromValue = @0.0f ;
[ self.layer addAnimation:anim forKey:nil ] ;
}
}
}
@end
n.b。:我猜测了在将叠加层添加到地图视图时如何添加这些动画,但我还没有测试过它。你需要做实验。您可以在创建视图时设置它们。
更新:我测试了它,它似乎有效。