Swift Completion Handler for mapView.setRegion Animation?

好久不见. 提交于 2019-12-11 02:19:34

问题


I'm trying to figure out how to tell when the animation is finished for the following:

self.mapView.setRegion(MKCoordinateRegionForMapRect(mapRect), animated: true)

It doesn't look like setRegion supports a completion handler like other commands.

I know how to create a generic completion handler using something like this: How could I create a function with a completion handler in Swift?

But I don't know what variable to check to verify the animation has completed.


回答1:


You can implement the MKMapViewDelegate protocol for this purpose. From the docs:

Because many map operations require the MKMapView class to load data asynchronously, the map view calls these methods to notify your application when specific operations complete.

This method should do what you want:

optional func mapView(_ mapView: MKMapView, regionDidChangeAnimated animated: Bool)

Tells the delegate that the region displayed by the map view just changed.



来源:https://stackoverflow.com/questions/48800111/swift-completion-handler-for-mapview-setregion-animation

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