在 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/