MKMapView setRegion如何停止动画 [英] MKMapView setRegion how to stop animation
本文介绍了MKMapView setRegion如何停止动画的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
你能帮我吗?我需要停止MkMapView方法setRegion:region动画:true.我需要设置带有选项的新区域以使其停止动画. 谢谢.
can u help me? I need to stop MkMapView method setRegion:region animated: true. I need to set new region animated with option to stop it. Thanks.
推荐答案
如果您创建另一个动画,但所创建的动画区域不同于现有动画,则会使现有动画无效.注意:如果我尝试创建一个新动画,但是对于相同的visibleMapRect,iOS只会忽略它.
If you create another animation but for a different region than the existing one, this will invalidate the existing one. Note: If I try to create a new animation but for same the visibleMapRect the iOS will just ignore it.
func stopZoom() {
//the trick: creating a region very similar to the existing one
var mapRegion:MKCoordinateRegion = MKCoordinateRegionForMapRect(self.mapView.visibleMapRect)
mapRegion.span.latitudeDelta = mapRegion.span.latitudeDelta + 0.000001
UIView.animateWithDuration(0.1, delay: 0.0, options: [], animations: {
let mapRegion:MKCoordinateRegion = mapRegion
self.mapView.setRegion(mapRegion, animated: true) //this will invalidate the other animations
}) { (completed: Bool) -> Void in
}
}
作为参考的startZoom方法:
for reference the startZoom method:
func startZoom() {
UIView.animateWithDuration(10, delay: 0.0, options: [UIViewAnimationOptions.CurveLinear, UIViewAnimationOptions.AllowUserInteraction, UIViewAnimationOptions.BeginFromCurrentState], animations: {
let mapRegion:MKCoordinateRegion = MKCoordinateRegionMakeWithDistance(self.coordinate, 500, 500)
self.mapView.setRegion(mapRegion, animated: true)
}) { (completed: Bool) -> Void in
}
}
花了很多时间来解决这个问题,希望对您有帮助.
Spent quite a lot of time to figure this out, I hope it will be helpful to you.
这篇关于MKMapView setRegion如何停止动画的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文