Mapkit,如何检测注释已加载 [英] Mapkit, how to detect annotations have loaded
问题描述
我想要在图钉已完成缩图动画时弹出注释标注。目前我可以用下面的方法模拟它:
- (void)showCallOut {
[myMapView selectAnnotation: [myMapView.annotations objectAtIndex:0] animated:YES];
}
在我的 viewDidLoad
[myMapView addAnnotation:annotation];
问题是你根本不能调出 [self showCallOut];
之后,因为在运行时,它在MapKit确认注释下拉之前响应。我需要创建一个延迟(想避免这种情况)或找到正确的方法来检测注释到位,然后运行 showCallOut
方法。
感谢以下提供解决方案的BitObvious:
- (void)mapView:(MKMapView *)mapView didAddAnnotationViews:(NSArray *)views {
[self performSelector:@selector(showCallOut)withObject:nil afterDelay :1];
}
尝试使用didAddAnnotationViews委托方法:
- (void)mapView:(MKMapView *)mapView didAddAnnotationViews:(NSArray *)views
{
[self showCallOut];
}
确保您的地图视图的委托已设置。
编辑:
如果您需要添加延迟,请尝试此操作(例如1/2秒延迟):
- (void)mapView:(MKMapView *)mapView didAddAnnotationViews:(NSArray *)views
{
[self performSelector:@selector(showCallOut)withObject:nil afterDelay:0.5];
}
I want the annotations callout to popup when the pin has finished it's drop animation. Currently I am able to simulate it with the following method:
- (void)showCallOut {
[myMapView selectAnnotation:[myMapView.annotations objectAtIndex:0] animated:YES];
}
In my viewDidLoad
is where my annotation is created
[myMapView addAnnotation:annotation];
The problem is that you simply can't callout [self showCallOut];
after that because at run time it responds before MapKit has "acknowledged" the annotation drop. I need to either create a delay (Would like to avoid this) or find the proper way to detect when annotations are in place and then run the showCallOut
method.
Thanks for any help!
Thanks to aBitObvious below for providing a solution:
- (void)mapView:(MKMapView *)mapView didAddAnnotationViews:(NSArray *)views {
[self performSelector:@selector(showCallOut) withObject:nil afterDelay:1];
}
Try using the didAddAnnotationViews delegate method:
- (void)mapView:(MKMapView *)mapView didAddAnnotationViews:(NSArray *)views
{
[self showCallOut];
}
Make sure your map view's delegate is set.
Edit:
If you need to add a delay regardless, then try this instead (example with 1/2 second delay):
- (void)mapView:(MKMapView *)mapView didAddAnnotationViews:(NSArray *)views
{
[self performSelector:@selector(showCallOut) withObject:nil afterDelay:0.5];
}
这篇关于Mapkit,如何检测注释已加载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!