我已经实现了 GMSMapViewDelegate
的三个方法,其中两个(markerInfoWindow
、willMove
)在 时按预期被调用当我点击“我的位置”按钮时,didTapMyLocationButtonForMapView
从未被触发。
初始化:
class MapViewController: UIViewController {
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
GMSServices.provideAPIKey("KEY")
mapView = GMSMapView(frame: view.frame)
mapView.settings.myLocationButton = true
mapView.padding = UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 0)
mapView.isMyLocationEnabled = true
mapView.delegate = self
view.insertSubview(mapView, at: 0)
}
}
委托(delegate)实现:
extension MapViewController: GMSMapViewDelegate {
func mapView(_ mapView: GMSMapView, markerInfoWindow marker: GMSMarker) -> UIView? {
...
return infoView
}
func mapView(_ mapView: GMSMapView, willMove gesture: Bool) {
...
}
func didTapMyLocationButtonForMapView(mapView: GMSMapView!) -> Bool {
...
return false
}
}
我尝试过:
- 在
viewDidLoad
中初始化。 - 更改
viewDidAppear
中方法的顺序(例如,在插入 View 后设置委托(delegate))。 - 将 Storyboard 中的类设置为
GMSMapView
而不是以编程方式添加。
但似乎没有任何帮助。有什么想法吗?
最佳答案
缺少 _
func didTapMyLocationButtonForMapView(_ mapView: GMSMapView!) -> Bool {
...
return false
}
关于ios - 未调用 didTapMyLocationButtonForMapView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48366731/