gpt4 book ai didi

iphone - 是否可以在 MKAnnotationView 而不是 MKPinAnnotationView 中调用 animatesDrop ?

转载 作者:行者123 更新时间:2023-12-03 18:31:33 27 4
gpt4 key购买 nike

你知道 MKPinAnnotationView 有一个方法“animatesDrop”可以用阴影将图钉注释从顶部动画到指向 map 上吗?好的,是否可以使用自定义图像来做到这一点?

最佳答案

您始终可以在 MKMapViewDelegate 方法中执行自定义动画。

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

可能是这样的(你不会得到花哨的阴影动画,如果你想要它,你需要自己做):

- (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 版本

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()
}
}

关于iphone - 是否可以在 MKAnnotationView 而不是 MKPinAnnotationView 中调用 animatesDrop ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2139222/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com