美文网首页傲视苍穹iOS《Objective-C》VIP专题
高德 ios 自定义气泡添加点击事件无效问题

高德 ios 自定义气泡添加点击事件无效问题

作者: 65067d1326a2 | 来源:发表于2016-03-30 16:35 被阅读2656次

在使用高德地图sdk开发的时候,需要自定义气泡吹出框,发现气泡添加的点击事件或者button都没响应

原因:自定义的气泡是添加到大头针上的,而大头针的size只有下面很小一部分,所以calloutView是在大头针的外面的。

而 iOS 按钮超过父视图范围是无法响应事件的处理方法。

在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 就是你需要点击的按钮

相关文章

网友评论

    本文标题:高德 ios 自定义气泡添加点击事件无效问题

    本文链接:https://www.haomeiwen.com/subject/dwfelttx.html