gpt4 book ai didi

swift - 将谷歌地图的 didTapAtCoordinate 方法与 UITapGestureRecognizer 结合使用

转载 作者:搜寻专家 更新时间:2023-11-01 05:38:00 25 4
gpt4 key购买 nike

我注意到:

func mapView(mapView: GMSMapView!, didTapAtCoordinate coordinate: CLLocationCoordinate2D) {
print("You tapped at \(coordinate.latitude), \(coordinate.longitude)")
}

正在覆盖手势识别器:

@IBOutlet weak var mapView: GMSMapView!
let aSelector : Selector = "tappedOnMap"
let tapGesture = UITapGestureRecognizer(target: self, action: aSelector)
mapView.userInteractionEnabled = true
tapGesture.numberOfTapsRequired = 1
mapView.addGestureRecognizer(tapGesture)

func tappedOnMap() {
print("Tapped")
}

“Tapped”从不打印,但“You tapped at so and so”会打印。

我的 map View 被拉伸(stretch)以填满 View 屏幕。似乎 didTapAtCoordinate 覆盖了 GestureRecognizer。 (我确信这一点,因为当我将 gesturerecognizer 附加到该 Controller 的 super View (最顶层 View ),并在 mapView 上禁用“用户交互”时,“Tapped”被打印出来。)如何调用这两种方法?

最佳答案

这是一个 worker 类(Class)来比较你做错了什么:

可能是:

  1. 没有调用 GMSMapViewDelegate

  2. MapView.delegate = self 未设置

  3. 缺少 func mapView(**_** MapView: GMSMapView, didTap marker: GMSMarker) -> Bool

    前面的下划线
    class CustomMapPicker: UIViewController, GMSMapViewDelegate
    {
    @IBOutlet weak var MapView: GMSMapView!

    override func viewDidLoad()
    {
    super.viewDidLoad()
    MapView.delegate = self
    let camera = GMSCameraPosition.camera(withLatitude: 25.2048, longitude: 55.2708, zoom: 10)
    MapView?.camera = camera
    MapView?.animate(to: camera)
    MapView?.isMyLocationEnabled = false
    }

    func mapView(_ MapView: GMSMapView, didTapAt coordinate: CLLocationCoordinate2D)
    {
    print("lat = " + "\(coordinate.latitude)" + " long = " + "\(coordinate.longitude)")
    }

    func mapView(_ MapView: GMSMapView, didTap marker: GMSMarker) -> Bool
    {
    return true
    }
    }

关于swift - 将谷歌地图的 didTapAtCoordinate 方法与 UITapGestureRecognizer 结合使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34535923/

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