ios - UIGestureRecognizer 不起作用并使应用变慢

标签 ios swift uinavigationcontroller location uigesturerecognizer

在 map View 中,我想做的是,如果用户触摸 map 中的任何地方,应用程序将停止更新位置..但似乎什么都没有发生,并且需要大约 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,我的应用程序运行缓慢且有延迟。对此有任何解决方案吗?

最佳答案

添加UITapGesture的正确方法

class DashVC: UIViewController, UIGestureRecognizerDelegate{
}

像这样在 viewdidload 中定义 tapsture

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

和行动

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

关于ios - UIGestureRecognizer 不起作用并使应用变慢,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39425152/

相关文章:

ios - 自定义 TableViewCell 的 UIImageView 导出 nil

ios - 获取有关 ARKit 中捏合手势的详细信息

swift - 在 UINavigationController 中更改 UINavigationBar 的约束

ios - Xamarin iOS 导航栏 100% 透明

ios - 使用 navigationBarHidden 作为 getter 属性不会出错

iOS/iPhone SDK : Is there an event for when network is lost/back?

ios - CloudKit 处理 ChangeTokenExpired 错误

ios - 未处理的 Promise 拒绝 : ImageSource. setNativeSource() 需要 UIImage 实例

ios - 我找到了四种不同的方法来更改 Xcode 中的 iOS 状态栏。为什么会有这么多,有什么区别?

swift - 了解 Swift 索引、范围、距离