快速手势代表

时间:2018-02-27 17:00:26

标签: ios iphone maps gesture

我正在尝试实施HERE地图SDK手势。我添加了delegate和didRecivePan函数。平移手势由应用程序识别 问题是我的mapView在我的平移手势被使用时被冻结,并且它创建了像地图滚动一样的滞后,这使得UX真的很烦人。无论如何,这可以解决。

var follow : Bool = true;

@IBOutlet weak var mapView: NMAMapView!

let positionManager = NMAPositioningManager.self
let gestureMarker = NMAMapMarker.self   

override func viewDidLoad() {
    super.viewDidLoad()
    mapView.gestureDelegate = self
}

@objc func didLosePosition(){ print("Position lost")}

@objc func positionDidUpdate(){
    /* Possible solution but an ugly one!
    if(follow == true){
        mapView.gestureDelegate = self
    }else if(follow == false){
        mapView.gestureDelegate = nil
    }*/
    print("Follow \(follow)")
    print("position updated")
    let position = positionManager.sharedInstance().currentPosition
    print(position!.coordinates ?? "xx")
    if(follow){
    mapView.set(geoCenter:(position?.coordinates)!,animation: .linear)
    }
}

override func viewWillAppear(_ animated: Bool) {

    if(positionManager.sharedInstance().startPositioning()){
        // Register to positioning manager notifications
        NotificationCenter.default.addObserver(self, selector: #selector(self.positionDidUpdate), name: NSNotification.Name.NMAPositioningManagerDidUpdatePosition, object: positionManager.sharedInstance())
        NotificationCenter.default.addObserver(self, selector: #selector(self.didLosePosition), name: NSNotification.Name.NMAPositioningManagerDidLosePosition, object: positionManager.sharedInstance())
    }

    super.viewWillAppear(animated)
    mapView.zoomLevel = 17
    mapView.set(geoCenter: NMAGeoCoordinates(latitude:  45.921189263505788, longitude: 14.234863696633125),
                animation: .linear)
    let mapMarker = NMAMapMarker(geoCoordinates: NMAGeoCoordinates(latitude:  45.921189263505788, longitude: 14.234863696633125), icon: NMAImage(uiImage: UIImage(named: "driver") ?? UIImage())!)
    mapView.positionIndicator.isVisible = true;
    mapView.positionIndicator.isAccuracyIndicatorVisible = true
    mapView.positionIndicator.set(displayObject: mapMarker, toLayer: NMAMapLayerType.foreground)
    mapView.copyrightLogoPosition = NMALayoutPosition.centerRight
}

func mapView(_ mapView: NMAMapView, didReceivePan translation: CGPoint, at location: CGPoint) {
    follow = false

}

@IBAction func followButton(_ sender: UIButton) {
    follow = true
    mapView.set(geoCenter: (positionManager.sharedInstance().currentPosition?.coordinates)!,
                animation: .linear)
    mapView.zoomLevel = 17
}

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}

}

0 个答案:

没有答案