百度地图点击自定义标记不显示泡泡但能做其他操作

  • 问题:
    如下图所示,在设计的时候在地图上添加标志,但是点击的效果是跳转,而不是显示泡泡动画,或者显示泡泡动画之后点击泡泡动画跳转
1
  • 分析需求:
    1、往地图上添加自定义标志物
    2、标志物显示数据
    3、点击标志物不能显示泡泡,但是能实现其他的操作

  • 分布操作
    1、通过子类化<b>BMKAnnotationView</b>并重载<b>-initWithAnnotation:reuseIdentifier</b>将一个自定义的label添加自定义视图上,因为不能看是泡泡所以需要设置属性canShowCallout为No

- (id)initWithAnnotation:(id<BMKAnnotation>)annotation reuseIdentifier:(NSString *)reuseIdentifier{
    self  = [super initWithAnnotation:annotation reuseIdentifier:reuseIdentifier];
    if (self) {
        self.backgroundColor = [UIColor clearColor];
        self.image = [UIImage imageNamed:@"map_Animate"];
        _countLbl = [[UILabel alloc] initWithFrame:CGRectMake(5, 10, 30, 20)];
        _countLbl.textAlignment = NSTextAlignmentCenter;
        _countLbl.font = [UIFont systemFontOfSize:12];
        _countLbl.textColor = [UIColor whiteColor];
        _countLbl.backgroundColor = [UIColor clearColor];
        _countLbl.userInteractionEnabled = NO;
        [self addSubview:_countLbl];
        self.canShowCallout = NO;
    }
    return self;
}

2、子类化BMKPointAnnotation,并添加属性id

/*
 *自定义Annotation
 */
@interface CustomeAnnotation : BMKPointAnnotation
@property (nonatomic, assign) NSUInteger releatedId;

@end

3、添加CustomeAnnotation的实例到mapview时,需要切记一定要设置title属性,具体原因是,如果不设置的话,

- (void)mapView:(BMKMapView *)mapView didSelectAnnotationView:(BMKAnnotationView *)view

此方法只会响应一次,title属性只会影响到泡泡,而我们设置了泡泡不现实,所以无论title属性设置为什么都不会影响到界面

4、实现viewForAnnotation方法

5、实现didSelectAnnotationView方法,在里面需要设置view.selected = NO

 - (void)mapView:(BMKMapView *)mapView didSelectAnnotationView:(BMKAnnotationView *)view{
    view.selected = NO;
    
   /**
    一些其他的操作,如跳转
    **/
}

补充:
1、开启定位之后点击定位会弹出“ 我的位置”的泡泡,如果要不显示,可设置,userLocation.title= nil;

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 发现 关注 消息 iOS 第三方库、插件、知名博客总结 作者大灰狼的小绵羊哥哥关注 2017.06.26 09:4...
    肇东周阅读 12,229评论 4 61
  • Spring Cloud为开发人员提供了快速构建分布式系统中一些常见模式的工具(例如配置管理,服务发现,断路器,智...
    卡卡罗2017阅读 134,915评论 18 139
  • Android 自定义View的各种姿势1 Activity的显示之ViewRootImpl详解 Activity...
    passiontim阅读 173,242评论 25 708
  • 我站在窗边看着窗外迷离的灯火,时不时有车鸣声传入耳中。我猜测街上的车辆已经不多了,再过一天,重庆这座繁华的大都市比...
    清风自来阅读 398评论 4 4
  • 网上铺天盖地的广告 街上随处动人的标语 爱就买买买 爱就花花花 鲜花 情侣表 化妆品 保健品 烛光晚餐 烘焙 渲染...
    聆听幸福668阅读 312评论 2 2