Ma sous-classe personnalisée MKAnnotationView
ne définit pas sa propriété image
. Au lieu de cela, il gère certaines sous-vues à afficher.La zone tactile MKAnnotationView personnalisée est ridiculement étroite
Je implémente public func mapView(_ mapView: MKMapView, didSelect view: MKAnnotationView)
dans mon délégué pour détecter le contact d'annotation. Étant donné que la zone tactile est calculée par défaut avec la propriété image
, ma zone tactile de vue d'annotation est environ 1px grande. C'est ridicule.
Voilà comment je le crée:
init(annotation: JZStreamAnnotation) {
self.imageView = UIImageView.init(image: <an image>)
self.imageView.contentMode = .center
super.init(annotation: annotation, reuseIdentifier: JZStreamAnnotationView.identifier)
self.canShowCallout = false
self.imageView.center = CGPoint(x: self.frame.width/2, y: self.frame.height/2)
self.addSubview(self.imageView)
}
I read this post, mais je ne peux pas comprendre comment fonctionne la méthode hitTest. Voici une mise en œuvre qui font rien:
override func hitTest(_ point: CGPoint, with event: UIEvent?) -> UIView? {
if point.x > -100, point.x < 100, point.y > -100, point.y < 100 {
//return self
//return self.imageView
return super.hitTest(point, with: event)
}
return .none
}
A breapoint situé dans les if
feux de clause, mais le retour tout (super
/self
/imageView
) ne fait rien.
Enfin, si je mets en œuvre hitTest comme ceci:
override func hitTest(_ point: CGPoint, with event: UIEvent?) -> UIView? {
return .none
}
et si je clic sur mon annotationView centre exact, la méthode déléguée public func mapView(_ mapView: MKMapView, didSelect view: MKAnnotationView)
si tiré!
Un conseil pour agrandir la zone tactile?