gpt4 book ai didi

ios - UITapGestureRecognizer 不适用于 Google Maps SDK

转载 作者:搜寻专家 更新时间:2023-10-31 08:26:25 32 4
gpt4 key购买 nike

我有一个带有一些自定义 UIView 的 mapViewController(只有两个带有一些背景的标签)。我想在点击这个 UIView 后显示新的 ViewController。

因此,我的自定义 UIView 代码(这是其他情况下的有效解决方案):

 tapGestureRecognizer = UITapGestureRecognizer(target: self, action: "checkGesture:")
tapGestureRecognizer.numberOfTapsRequired = 1
self.userInteractionEnabled = true
self.addGestureRecognizer(tapGestureRecognizer)

func checkGesture(sender: UITapGestureRecognizer) {
print("it works")
}

谁能告诉我这里有什么问题吗?

编辑(已解决): 因此,我尝试将此自定义 UIView 放在另一个 ViewController 上,它可以正常工作。看来这个问题的主要根源是我的 MapViewController 中的下一部分代码:

let mapView = GMSMapView.mapWithFrame(CGRectZero, camera:camera)
self.view = mapView

没有最后一行 (self.view = mapView),我的自定义 UIView 可以工作(但我没有任何 map ,所以我不得不稍微更改此代码)。

let mapView = GMSMapView.mapWithFrame(CGRectMake(0, 0, self.view.frame.width, self.view.frame.height), camera:camera)
self.view.addSubview(mapView)

最佳答案

如果您不想将 GMSMapView 添加为 subview ,我认为最好的解决方案是:

  1. GMSMapViewDelegate 添加到您的 ViewController

  2. ViewControllerviewDidLoad 上添加 myMapView.delegate = self

  3. 同时添加如下函数:

    func mapView(_ mapView: GMSMapView, didTapAt coordinate: CLLocationCoordinate2D) {
    print("!map tapped!")
    }

关于ios - UITapGestureRecognizer 不适用于 Google Maps SDK,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32228560/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com