以编程方式添加MapView

时间:2017-08-07 01:40:43

标签: swift3 mkmapview

我正在尝试以编程方式将Map View添加到我的一个View Controllers中。以下是我到目前为止的情况:

let mapView: MKMapView = {

        let map = MKMapView()

        map.translatesAutoresizingMaskIntoConstraints = false

        map.mapType = MKMapType.standard
        map.isZoomEnabled = true
        map.isScrollEnabled = true

        return map
    }()


 override func viewDidLoad() {
        super.viewDidLoad()

        view.addSubview(mapView)

        //Mark: MapView

        mapView.centerXAnchor.constraint(equalTo: view.centerXAnchor).isActive = true
        mapView.centerYAnchor.constraint(equalTo: view.centerYAnchor).isActive = true
        mapView.heightAnchor.constraint(equalToConstant: 200).isActive = true
        mapView.widthAnchor.constraint(equalToConstant: 200).isActive = true

        view.backgroundColor = UIColor.white
    }

然而,当我加载这个视图控制器时,我得到一个空白的白色屏幕。我在这里错过了什么吗?

0 个答案:

没有答案