用于MapView.setRegion动画的Swift完成处理程序? [英] Swift Completion Handler for mapView.setRegion Animation?
问题描述
我正在尝试找出如何确定何时完成以下动画的操作:
I'm trying to figure out how to tell when the animation is finished for the following:
self.mapView.setRegion(MKCoordinateRegionForMapRect (mapRect),动画:true)
它看起来不像 setRegion
支持像其他命令一样的完成处理程序。
It doesn't look like setRegion
supports a completion handler like other commands.
我知道如何使用类似这样的方式创建通用完成处理程序:
如何在Swift中使用完成处理程序创建函数?
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.
推荐答案
您可以实现 MKMapViewDelegate
协议。从文档中:
You can implement the MKMapViewDelegate
protocol for this purpose. From the docs:
由于许多地图操作都需要MKMapView类来异步加载数据
,因此地图视图将这些方法称为具体操作完成后,通知您的
应用程序。
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.
这篇关于用于MapView.setRegion动画的Swift完成处理程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!