MapBox iOS SDK:添加地图事件

时间:2016-04-20 06:42:25

标签: ios swift mapbox mapbox-gl

我正在尝试使用最新的MapBox iOS idk(3.2)设置iOS应用。我多少寻求互联网,我找不到如何将地图事件添加到mapview的示例。

例如:我想在地图空闲时添加一个事件。有什么建议吗?

更新

我认为这是正确的实施方法:

func mapView(mapView: MGLMapView, regionDidChangeAnimated animated: Bool) {


}

1 个答案:

答案 0 :(得分:2)

If you’re asking how to use delegate methods, here’s how:

import Mapbox

// Declare conformance to the MGLMapViewDelegate protocol
class ViewController: UIViewController, MGLMapViewDelegate {

    var mapView: MGLMapView!

    override func viewDidLoad() {
        super.viewDidLoad()

        mapView = MGLMapView(frame: view.bounds)
        mapView.autoresizingMask = [.FlexibleWidth, .FlexibleHeight]
        view.addSubview(mapView)

        // Set the delegate property of our map view to self after instantiating it.
        mapView.delegate = self
    }

    func mapView(mapView: MGLMapView, regionDidChangeAnimated animated: Bool) -> Bool {
        // look at mapView properties and do something
    }
}

See https://www.mapbox.com/ios-sdk/examples/ for examples of how to implement basic features with the Mapbox iOS SDK.