美文网首页
高德地图官方提供的自定义气泡点击事件解决方法

高德地图官方提供的自定义气泡点击事件解决方法

作者: 迷途小少年 | 来源:发表于2017-08-03 17:40 被阅读0次

按照高德官方的思路集成之后,会发现气泡点击事件触发不了,很头疼,到网上找了很多解决方法,都是千篇一律,也解决不了问题,实在很气愤。写出自己拙劣的办法暂时解决这一问题,望大家再碰到这件事的时候能看到我的思路帮助大家解决问题,同时也想向大家请教更好的方法!

按照大家在高德官方Api提示集成的思路就不多说了,大家都是大神,不解释!然最后运行起来发现气泡点击不了,官方的解释如下:

自定义annotationView的弹出框. 注意:不会触发-(void)mapView: didAnnotationViewCalloutTapped: since 5.0.0

 重点来了,网上一系列的解决方法是


- (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;}


官方没有加buuton,我对这段代码进行了修改如下:


- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event {

UIView *view = [super hitTest:point withEvent:event];

if (view == nil) {

CGPoint tempoint = [self.calloutView convertPoint:point fromView:self];

if (CGRectContainsPoint(self.calloutViewbounds, tempoint))

{

view = self.calloutView;

[[NSNotificationCenter defaultCenter] postNotificationName:@"remove" object:self.annotation.title];

[view removeFromSuperview];

}

return view;


在这一块post 出去一个通知,在调用Map地图的Controller里监听post 的通知:

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(click:) name:@"remove" object:nil]; 

selector方法

-(void)click:(NSNotification *)info;

接受object里面的内容就可以了,post 出的object 可以是你定义的任何形式,模型字典亦可,我这边只是做简单的数据输出,至此就完成了数据的交互和UI交互。

结尾语:

第一次写文章,也许在别人看来这篇文章毫无价值,但还是愿意将自己的一点点心得分享出去 ,也许不是最好的,但也是万千方法的千万分之一,接下来的日子会继续更新好玩的,以便给大家带来方便。

不喜勿喷

相关文章

网友评论

      本文标题:高德地图官方提供的自定义气泡点击事件解决方法

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