我正在尝试使用Xcode 6.3和Swift做iOS应用程序。我使用MKMapView来跟踪用户的位置。问题是,如果我滚动地图,我立即返回到用户位置。这是我的代码:无法滚动MKMapView。
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
}
和
func locationManager(manager:CLLocationManager, didUpdateLocations locations:[AnyObject]) {
let spanX = 0.007
let spanY = 0.007
var newRegion = MKCoordinateRegion(center: theMap.userLocation.coordinate, span: MKCoordinateSpanMake(spanX, spanY))
theMap.setRegion(newRegion, animated: false)
theMap.scrollEnabled = true
}
如果我滚动地图,1秒后,我返回到用户的位置。我应该改变setRegion方法的位置吗?
MKCoordinateRegion(中心:这theMap.userLocation.coordinate将返回给用户位置..... –