我正在尝试弄清楚如何判断以下动画何时完成:
self.mapView.setRegion(MKCoordinateRegionForMapRect(mapRect), 动画: true)
看起来 setRegion
不像其他命令那样支持完成处理程序。
我知道如何使用类似这样的东西创建一个通用的完成处理程序: How could I create a function with a completion handler in Swift?
但我不知道要检查什么变量来验证动画是否已完成。
最佳答案
您可以实现MKMapViewDelegate
protocol以此目的。来自文档:
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.
这个方法应该做你想做的:
optional func mapView(_ mapView: MKMapView, regionDidChangeAnimated animated: Bool)
Tells the delegate that the region displayed by the map view just changed.
关于mapView.setRegion 动画的 Swift 完成处理程序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48800111/