ios - MKMapView setRegion 如何停止动画

标签 ios animation mkmapview mapkit

你能帮帮我吗?我需要停止 MkMapView 方法 setRegion:region animated: true。我需要设置新区域动画并选择停止它。 谢谢。

最佳答案

如果您创建另一个动画但针对与现有动画不同的区域,这将使现有动画无效。注意:如果我尝试创建一个新动画,但对于相同的 visibleMapRect,iOS 将忽略它。

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方法:

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
}

花了很多时间弄明白了,希望对你有所帮助。

关于ios - MKMapView setRegion 如何停止动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28066239/

相关文章:

javascript - 动画中的相对旋转

ios - 如何在单击表格 View 中的单元格时获取 map View 上的注释?

ios - 按钮图像看起来颜色相反

ios - 如何在 MapView IOS 中创建折线

ios - UIAlertController 出现在奇怪的位置

objective-c - initWithNibName 如何工作?

reactjs - 成帧器运动退出动画不起作用(使用 react 和动画存在)

javascript - 为什么彩色球越过页面边缘继续下降

mkmapview - [mapkit]放大 map ,图钉会随着 map 移动

ios - Xcode Swift 删除 MKPolyline