高德地图自定义标注的气泡时,不能响应单击事件吗?

公司项目要用高德的ios sdk开发一些功能,
然后我自定义的气泡,想要在上面加个button,但是点击button 时整个气泡都消失了,点击气泡的任何地方都是如此,是把这个事件都过滤掉了吧?
怎么样才能让气泡响应单击事件?

http://bbs.amap.com/thread-17425-1-1.html

解决了吗 楼主 教教我

同样的问题,在网上找了很久都没找到结果。
还是把我的解决方法贴上来吧,希望对有需要的人有帮助。

  • (MAAnnotationView *)mapView:(MAMapView *)mapView viewForAnnotation:(id)annotation { } 因为自定义的气泡是添加到大头针上的,而大头针的size只有下面很小一部分,所以calloutView是在大头针的外面的。 而 iOS 按钮超过父视图范围是无法响应事件的处理方法。所以就要重写hittest方法。

在CustomAnnotationView.m中重写hittest方法:

  • (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event { UIView *view = [super hitTest:point withEvent:event]; if (view == nil) { CGPoint tempoint = [self.calloutView.navBtn convertPoint:point fromView:self]; if (CGRectContainsPoint(self.calloutView.navBtn.bounds, tempoint)) { view = self.calloutView.navBtn; } } return view; }

这里的self.calloutView.navBtn 就是你需要点击的按钮