我已经设置了implemented GMSMapViewDelegate
,并将其设置为self,但仍然无法使任何委托函数工作。下面是我的代码示例:
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函数都没有打印任何内容。我已经检查了委托并知道它设置正确。我是否遗漏了什么?
2条答案
按热度按时间3wabscal1#
所以我想在
if mapView == nil { mapView = GMSMapView() }
我在后面的函数中设置了实际的边界
mapView = GMSMapView.mapWithFrame(CGRectMake(0,0,self.view.frame.size.width, self.view.frame.size.height), camera: camera)
和一旦我把mapView.delegate = self
之后,它的工作!euoag5mw2#
对我来说,修复不是从UIView的故事板连接检查器设置委托。即使我已经通过代码设置了它,但它不起作用。
转到情节提要,选择您的UIView,然后在身份检查器中添加类名GMSMapView
See Screeshot 1
然后点击连接检查器,在出口你会看到委派。拖动它到你的视图控制器。
see Screeshot 2