子视图阻止iOS上的MapBox mapView手势识别器

问题描述

我有一个iOS应用,其MapBox MGLMapView已添加到基本ViewController中。当我在mapView上方的ViewController中添加第二个UIView时,mapView上的手势识别器有时无法识别手势。

// ViewController

...

var mapView: MGLMapView = MGLMapView()

override func viewDidLoad() {
    super.viewDidLoad()

    mapView = MGLMapView(frame: view.bounds,styleURL: url)
    mapView.autoresizingMask = [.flexibleWidth,.flexibleHeight]
    mapView.delegate = self
    mapView.allowsTilting = false
    mapView.showsUserLocation = true
        
    view.addSubview(mapView)
    self.view.sendSubviewToBack(mapView)

    ...

}

...

let rect = MapRect()
view.addSubview(rect)
rect.center = CGPoint(x: UIScreen.main.bounds.midX,y: UIScreen.main.bounds.midY)

在将MapRect()添加到视图之前,mapView中的所有手势识别都可以正常工作。

// Map Rect

class MapRect: UIView {

    ...

    init() {
        self.backgroundColor = .clear
        self.layer.cornerRadius = 0

        self.isUserInteractionEnabled = true

        // Add pan gesture recognizer to move the rect around
        let panGestureRecognizer = UIPanGestureRecognizer(target:self,action:#selector(dragSymbol(_:)))
        panGestureRecognizer.maximumNumberOftouches = 1
        panGestureRecognizer.minimumNumberOftouches = 1
        self.addGestureRecognizer(panGestureRecognizer)

        // Add pinch gesture recognizer to resize rect
        let pinchGestureRecognizer = UIPinchGestureRecognizer(target:self,action:#selector(resizeSymbol(_:)))
        self.addGestureRecognizer(pinchGestureRecognizer)
    }
}

另外,当我添加MapRect()时,UIView中的手势识别器可以正常工作。我尝试设置MapRect()的背景色,以查看视图是否超出了我的预期范围,但并非如此。

最后不确定这是相关的还是偶然的,但似乎手势识别器在从MapRect()的边缘开始延伸的屏幕区域上失败的机会更多

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)