showing callout after moving mapview

折月煮酒 提交于 2019-12-01 23:13:42

问题


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.

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.


回答1:


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];
});


来源:https://stackoverflow.com/questions/10047596/showing-callout-after-moving-mapview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!