1

我想为添加为 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];
4

2 回答 2

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;
        }];
    }
}
于 2012-08-24T13:04:17.117 回答
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

注意:在将叠加层添加到地图视图时,我猜测了如何添加这些动画,但我还没有测试过。您将需要进行实验。您也许可以在创建视图时设置它们。

更新:我测试了它,它似乎工作。

于 2012-09-04T17:48:31.387 回答