通缉:如何可靠,一致地选择MKMapView注释 [英] Wanted: How to reliably, consistently select an MKMapView annotation

查看:150
本文介绍了通缉:如何可靠,一致地选择MKMapView注释的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在调用 MKMapView setCenterCoordinate:animated:方法(没有动画)之后,我想调用 selectAnnotation:animated:(使用动画)以便从新居中的图钉中弹出注释。

After calling MKMapView's setCenterCoordinate:animated: method (without animation), I'd like to call selectAnnotation:animated: (with animation) so that the annotation pops out from the newly-centered pushpin.

现在,我只是观察 mapViewDidFinishLoadingMap:,然后选择注释。但是,这是有问题的。例如,当不需要加载其他地图数据时,不会调用此方法。在这些情况下,我的注释未被选中。 :(

For now, I simply watch for mapViewDidFinishLoadingMap: and then select the annotation. However, this is problematic. For instance, this method isn't called when there's no need to load additional map data. In those cases, my annotation isn't selected. :(

很好。我可以在设置中心坐标后立即调用它。啊,但在那例如, 可能会加载地图数据(但尚未完成加载)。我冒险过早地调用它,动画最多变得不稳定。

Very well. I could call this immediately after setting the center coordinate instead. Ahh, but in that case it's possible that there is map data to load (but it hasn't finished loading yet). I'd risk calling it too soon, with the animation becoming spotty at best.

因此,如果我理解正确,这不是知道我的坐标是否可见的问题,因为它可能会偏离几乎一段距离并且必须加载新的地图数据。 em>这是一个知道是否需要加载新地图数据,然后相应地采取行动的问题。

Thus, if I understand correctly, it's not a matter of knowing if my coordinate is visible, since it's possible to stray almost a screenful of distance and have to load new map data. Rather, it's a matter of knowing if new map data needs to be loaded, and then acting accordingly.

关于如何实现这一目标的任何想法,或者如何在将地图视图重新定位在注释所在的坐标上之后以其他方式(可靠地)选择注释?

Any ideas on how to accomplish this, or how to otherwise (reliably) select an annotation after re-centering the map view on the coordinate where that annotation lives?

线索赞赏 - 谢谢!

推荐答案

我遇到了同样的问题,但发现了什么似乎是一个可靠而合理的解决方案:

I ran into the same problem, but found what seems like a reliable and reasonable solution:


  1. 实现委托方法mapView:didAddAnnotationViews:。当我尝试在委托方法中直接选择注释时,标注随引脚丢弃!这看起来很奇怪,所以我稍加延迟半秒。

  1. Implement the delegate method mapView:didAddAnnotationViews:. When I tried selecting the annotation directly within the delegate method, the callout dropped with the pin! That looked odd, so I add a slight delay of a half-second.

-(void)mapView:(MKMapView *)mapView didAddAnnotationViews:(NSArray *)views {
    [self performSelector:@selector(selectInitialAnnotation)
          withObject:nil afterDelay:0.5];
}


  • 按照您的预期选择初始注释,但调用selectAnnotation :动画;

  • Select the initial annotation as you'd expect, but calling selectAnnotation:animated;

    -(void)selectInitialAnnotation {
        [self.mapView selectAnnotation:self.initialAnnotation animated:YES];
    }
    


  • 似乎 selectAnnotation:animated:在某些情况下不会被调用。与 MKMapView docs

    It seems that selectAnnotation:animated: is not called under some conditions. Compare with MKMapView docs:


    如果指定的注释不在屏幕上,因此不是
    有一个关联的注释视图,此方法无效。

    If the specified annotation is not onscreen, and therefore does not have an associated annotation view, this method has no effect.

    这篇关于通缉:如何可靠,一致地选择MKMapView注释的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆