我的自定义MKAnnotationView
子类不要设置它的image
属性。相反,它处理一些子视图来显示。自定义MKAnnotationView触摸区域可笑地缩小
我在我的委托中执行public func mapView(_ mapView: MKMapView, didSelect view: MKAnnotationView)
来检测注释触摸。
由于触摸区域默认使用image
属性进行计算,因此我的注释视图触摸区域大约为1px。这是荒唐的。
这是我如何创建它:
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,但我想不通的则hitTest方法是如何工作的。在这里,让没有实现:
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
}
地处if
条款触发一个breapoint,但无论返回(super
/self
/imageView
)什么都不做。
最后,如果我实现则hitTest这样的:
override func hitTest(_ point: CGPoint, with event: UIEvent?) -> UIView? {
return .none
}
,如果我在我的annotationView确切中心CLIC,如果解雇了public func mapView(_ mapView: MKMapView, didSelect view: MKAnnotationView)
委托方法!
任何建议放大触摸区?