要是同樣的問題,我斷碼看起來是這樣的:
class ViewController: UIViewController {
fileprivate var mapView = MKMapView()
override func viewDidLoad() {
super.viewDidLoad()
// Add the mapView to the VC
mapView.translatesAutoresizingMaskIntoConstraints = false
view.addSubview(mapView)
mapView.leftAnchor.constraint(equalTo: view.leftAnchor).isActive = true
mapView.rightAnchor.constraint(equalTo: view.rightAnchor).isActive = true
mapView.topAnchor.constraint(equalTo: view.topAnchor).isActive = true
mapView.bottomAnchor.constraint(equalTo: view.bottomAnchor).isActive = true
}
}
因爲它在iOS的11變成了它不喜歡具有的MKMapView初始化視圖控制器加載之前即viewDidLoad中(),所以FIX被更改爲:
class ViewController: UIViewController {
fileprivate var mapView: CSMapView?
override func viewDidLoad() {
super.viewDidLoad()
// Init instance here.
mapView = CSMapView()
// Add the mapView to the VC
mapView?.translatesAutoresizingMaskIntoConstraints = false
...
}
}
還試圖把它在初始化方法,但這並沒有爲我工作:
override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: Bundle?) {
super.init(nibName: nibNameOrNil, bundle: nibBundleOrNil)
mapView = MKMapView()
}
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
mapView = MKMapView()
}
您是否在視圖控制器中的viewDidLoad方法中初始化MapView?如果是這樣,請嘗試將其移動到viewDidAppear方法。 –
@KosukeOgawa剛剛嘗試過,但沒有任何區別。也不是我想要的東西,因爲這會破壞可用性,因爲地圖會經常重新加載。 – Christoffer
現在我正在等待它,看看它是否會在以後的測試版中得到解決。否則我會回到試圖找到解決方案。 – Christoffer