我正在嘗試使用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將返回給用戶位置..... –