我已经设置了实现的GMSMapViewDelegate
,将其设置为self,但我仍然无法让任何委托(delegate)函数工作。以下是我的代码示例:
class UserViewController: UIViewController, CLLocationManagerDelegate, GMSMapViewDelegate {
var mapView: GMSMapView!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
if mapView == nil {
mapView = GMSMapView()
}
mapView.delegate = self
}
func mapView(mapView: GMSMapView, didChangeCameraPosition position: GMSCameraPosition) {
print(position)
}
func mapView(mapView: GMSMapView, willMove gesture: Bool) {
print(gesture)
}
func mapView(mapView: GMSMapView, idleAtCameraPosition position: GMSCameraPosition) {
print(position)
}
mapView 函数都没有打印任何内容。我已经检查了代表并知道它设置正确。我错过了什么吗?
最佳答案
所以我认为在之后设置委托(delegate)
如果mapView == nil {
map View = GMSMapView()
}
是正确的,但事实并非如此。我在后面的函数中设置了实际边界
mapView = GMSMapView.mapWithFrame(CGRectMake(0,0,self.view.frame.size.width, self.view.frame.size.height), 相机: 相机)
一旦我放置了 mapView.delegate = self
之后,它就起作用了!
关于ios - iOS 上未调用 GMSMapViewDelegate 函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39066714/