Ios 无法滚动MKMapView。
我正在尝试使用Xcode 6.3和swift开发iOS应用程序。我使用MKMapView跟踪用户位置。问题是,如果我滚动地图,我会立即返回到用户位置。这是我的代码:Ios 无法滚动MKMapView。,ios,swift,Ios,Swift,我正在尝试使用Xcode 6.3和swift开发iOS应用程序。我使用MKMapView跟踪用户位置。问题是,如果我滚动地图,我会立即返回到用户位置。这是我的代码: override func viewDidLoad() { super.viewDidLoad() manager = CLLocationManager() manager.delegate = self manager.desiredAccuracy = kCLLocationAcc
override func viewDidLoad() {
super.viewDidLoad()
manager = CLLocationManager()
manager.delegate = self
manager.desiredAccuracy = kCLLocationAccuracyBest
manager.requestAlwaysAuthorization()
manager.startUpdatingLocation()
theMap.delegate = self
theMap.mapType = MKMapType.Standard
theMap.zoomEnabled = true
theMap.addGestureRecognizer(longPress)
theMap.scrollEnabled = true
}
及
如果我滚动地图,1秒钟后我返回到用户位置。我是否应该更改setRegion方法位置?您需要在滚动地图时进行检测,可能是通过实现
mapView(\uuu:regionWillChangeAnimated:)
中定义的MKMapViewDelegate
方法。在此方法中,您需要将地图视图的userTrackingMode
属性设置为.None
。当用户平移或缩放theMap
变量时,将调用您的实现。因此,您应该努力使实现尽可能轻量级,因为对于单个平移或缩放手势,可以多次调用它
func mapView(mapView: MKMapView!, regionWillChangeAnimated animated: Bool) {
if you want to stop tracking the user {
mapView.userTrackingMode = .None
}
}
如果要再次开始跟踪用户的位置,请将该属性更改回。Follow
或。FollowWithHeading
:
enum MKUserTrackingMode : Int {
case None // the user's location is not followed
case Follow // the map follows the user's location
case FollowWithHeading // the map follows the user's location and heading
}
MKCoordinateRegion(中心:theMap.userLocation.coordinate这将返回用户位置…..非常感谢Ndmeri。我解决了阅读文档的问题。我将“theMap.setRegion(newRegion,动画:false)”放在locationManager方法中的方法和add a map tap侦听器,我在其中使用manager.stopUpdateLocation()方法禁用更新位置。谢谢!
enum MKUserTrackingMode : Int {
case None // the user's location is not followed
case Follow // the map follows the user's location
case FollowWithHeading // the map follows the user's location and heading
}