本文介绍了在移动mapview后显示标注的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在地图视图上有几个注释.选择其中一个(启用了标注)后,我希望地图以其为中心.我在didSelectAnnotationView中调用[mapView setCenterCoordinate:coordinate animated:YES];来实现这一目标.

I have several annotations on a mapview.After selecting one of them (callout enabled) I want the map to center on it.I call[mapView setCenterCoordinate:coordinate animated:YES];in didSelectAnnotationViewto achieve that.

它有效,但并非总是如此-基本上是在没有足够的空间来显示标注,地图移动并选择了注释时,但标注未显示(无论是否以动画形式移动都无关紧要) .如果我自己不使用setCenterCoordinate移动地图,则在选择注释后,地图会自动移动(略微移动)以显示标注,并且每次都可以使用.

It works but not always - basically when there is not enough room left to show the callout, the map moves and the annotation is selected, but the callout is not shown (doesn't matter if the move is animated or not).If I don't move the map myself with setCenterCoordinate, after selecting a annotation the map gets automatically moved (just slightly) to show the callout and it works everytime.

任何想法如何使其适用于我的情况?总结一下,我想将地图集中在选定的注释上并显示标注.

Any ideas how to make it work in my case?To sum up I want to center the map on the selected annotation and show the callout.

推荐答案

通过在didSelectAnnotationView中稍有延迟地调用setCenter来解决该问题:

Solved it by calling setCenter with a slight delay in didSelectAnnotationView:

dispatch_time_t dt = dispatch_time(DISPATCH_TIME_NOW, 0.2 * NSEC_PER_SEC);
dispatch_after(dt, dispatch_get_main_queue(), ^(void)
{
    [mapView setCenterCoordinate:view.annotation.coordinate animated:YES];
});

这篇关于在移动mapview后显示标注的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-04 22:06