Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
472 views
in Technique[技术] by (71.8m points)

iphone - Is it possible to call animatesDrop in a MKAnnotationView rather than MKPinAnnotationView?

do you know that MKPinAnnotationView has a method "animatesDrop" to animate a pin annotation from the top to point on the map with a shadow? OK, is it possible do this with a custom image??

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You can always do your custom animation in MKMapViewDelegate method.

- (void)mapView:(MKMapView *)mapView didAddAnnotationViews:(NSArray *)views

Probably something like that (you won't get the fancy shadow animation, if you want it you need to do it yourself) :

- (void) mapView:(MKMapView *)mapView didAddAnnotationViews:(NSArray *)views {
    CGRect visibleRect = [mapView annotationVisibleRect]; 
    for (MKAnnotationView *view in views) {
       CGRect endFrame = view.frame;

       CGRect startFrame = endFrame; startFrame.origin.y = visibleRect.origin.y - startFrame.size.height;
       view.frame = startFrame;

       [UIView beginAnimations:@"drop" context:NULL]; 
       [UIView setAnimationDuration:1];

       view.frame = endFrame;

       [UIView commitAnimations];
    }
}

Swift Version

func mapView(mapView: MKMapView, didAddAnnotationViews views: [MKAnnotationView]) {
    let visibleRect = mapView.annotationVisibleRect

    for view:MKAnnotationView in views{
        let endFrame:CGRect = view.frame
        var startFrame:CGRect = endFrame
        startFrame.origin.y = visibleRect.origin.y - startFrame.size.height
        view.frame = startFrame;

        UIView.beginAnimations("drop", context: nil)
        UIView.setAnimationDuration(1)

        view.frame = endFrame;

        UIView.commitAnimations()
    }
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...