UIGestureRecognizer不起作用,使应用程序变慢

时间:2016-09-10 10:31:47

标签: ios swift uinavigationcontroller location uigesturerecognizer

在地图视图中,我希望如果用户触摸地图中的任何位置,应用程序停止更新位置..但似乎没有任何反应,操作在应用程序中运行需要大约10-15秒(使应用程序确实慢和滞后)我一直在使用这段代码:

 @IBOutlet var Map: MKMapView!

    let locationManager = CLLocationManager()
     override func viewDidLoad() {
        super.viewDidLoad()
        StopUpdate.hidden = true
        Longi.hidden = true
        Lati.hidden = true
        locationManager.delegate = self
        locationManager.desiredAccuracy = kCLLocationAccuracyBest
        locationManager.requestWhenInUseAuthorization()
        locationManager.requestLocation()
        locationManager.startUpdatingLocation()
        locationManager.stopUpdatingLocation()
    self.view.addGestureRecognizer(UIGestureRecognizer(target: self, action: "tapClose"))
}

func tapClose(gesture: UITapGestureRecognizer){
    locationManager.stopUpdatingLocation()
    StopUpdate.hidden = true
    UpdateLocation.hidden = false
}

由于GestureRecognizer,我的应用程序很慢而且很迟钝。有什么解决方案吗?

1 个答案:

答案 0 :(得分:1)

添加UITapGesture的正确方法

class DashVC: UIViewController, UIGestureRecognizerDelegate{
}

在viewdidload中定义tapgesture,就像这样

let tapDashBoard = UITapGestureRecognizer(target: self, action: #selector(DashVC.DashBoardTapped(_:)))
    tapDashBoard.delegate = self
    view.addGestureRecognizer(tapDashBoard)

和行动

    func DashBoardTapped(sender: UITapGestureRecognizer? = nil) {
}