我有mapbox地图和几个按钮。问题是当用户双击任何按钮映射放大。如何禁用此功能?即使用户双击缩小,地图也会放大,然后缩小。我尝试但在iOS中我不知道如何,对于android我知道解决方案。当双击按钮地图放大并且按钮委托双击时,下面的代码不起作用...
let singleTap4 = UITapGestureRecognizer(target: self, action: #selector(MainViewController.tapPatrolaBtn))
singleTap4.numberOfTapsRequired = 1
singleTap4.numberOfTouchesRequired = 1
patrolaButton.isUserInteractionEnabled = true
patrolaButton.addGestureRecognizer(singleTap4)
patrolaButton.addTarget(self, action: #selector(multipleTap(_:event:)), for: UIControlEvents.touchDownRepeat)
@objc func multipleTap(_ sender: UIButton, event: UIEvent) {
let touch: UITouch = event.allTouches!.first!
if (touch.tapCount == 2) {
}
}
答案 0 :(得分:0)
在这里你也需要处理双击手势。
如果您使用的是双击手势识别器,那么double tapevent将不会委托给mapbox地图,而mapbox zoom事件也不会调用
使用以下代码: -
button.addTarget(self, action: #selector(multipleTap(_:event:)), for: UIControlEvents.touchDownRepeat)
//Don't do in action
func multipleTap(_ sender: UIButton, event: UIEvent) {
let touch: UITouch = event.allTouches!.first!
if (touch.tapCount == 2) {
}
}
答案 1 :(得分:0)
我找到解决方案,点击按钮我运行此代码,因此它暂时禁用地图手势:
mapView.isZoomEnabled = false
DispatchQueue.main.asyncAfter(deadline: .now() + 0.6) {
self.mapView.isZoomEnabled = true }