百度地图 --给大头针加tag值

分篇介绍最新百度地图相关应用
一、环境配置:
https://www.jianshu.com/p/be592ed98ebf
二、显示与定位:
https://www.jianshu.com/p/154c7840ffa5
三、根据经纬度描点:
https://www.jianshu.com/p/a4065c3f0457
四、大头针与气泡:
https://www.jianshu.com/p/bb8f8f3c1ef1
五、给大头针加tag值:
https://www.jianshu.com/p/6023465da2e7
六、问题处理:
https://www.jianshu.com/p/c8b1449efea7

本篇介绍给大头针加tag值!

项目demo:
https://github.com/Dongxk/XKBMKMap.git

本篇效果:


方法:

在- (BMKAnnotationView *)mapView:(BMKMapView *)mapView viewForAnnotation方法中替换掉原先的BMKAnnotationView;

#pragma mark ---  BMKMapViewDelegate
- (BMKAnnotationView *)mapView:(BMKMapView *)mapView viewForAnnotation:(id<BMKAnnotation>)annotation{
    
    if ([annotation isKindOfClass:[self.pointAnnotation class]]) {
        //数组对应大头针
        paopaoIndex++;
        UIView *paopaoView = [UIView new];
        static NSString *identifier = @"XKAnnotationView";
//自定义的XKAnnotationView 替换掉原先的BMKAnnotationView
        XKAnnotationView *annotationView = [[XKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:identifier customView:paopaoView WithData: self.pointArray[paopaoIndex - 1] WithTag:1000 + paopaoIndex];
        return annotationView;
    }else{
        //定位大头针


    }
    return nil;
}

自定义AnnotationView

- (id)initWithAnnotation:(id<BMKAnnotation>)annotation reuseIdentifier:(NSString *)reuseIdentifier customView:(UIView *)detailView WithData:(NSDictionary *)dataDict WithTag:(NSInteger)tag{
    
    
    if (self = [super initWithAnnotation:annotation reuseIdentifier:reuseIdentifier]) {
        
        if (self) {
            
            [self setBounds:CGRectMake(0, 0, 100.f, 100.f)];
            self.canShowCallout = YES;
            self.centerOffset = CGPointMake(0, 0); //设置中心点偏移
            detailView.tag = tag;
            
            [self configCellWithData:dataDict];
            [self addSubview: detailView];
        }
    }
    return self;
}

具体请看demo:
demo

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

推荐阅读更多精彩内容

  • 用两张图告诉你,为什么你的 App 会卡顿? - Android - 掘金 Cover 有什么料? 从这篇文章中你...
    hw1212阅读 13,079评论 2 59
  • (一)自iOS 地图SDK v2.5.0起,为了对iOS8的定位能力做兼容,做了相应的修改,使用注意事项如下: 需...
    chulijun阅读 2,440评论 0 0
  • http://www.cnblogs.com/kenshincui/p/4125570.html 摘要: 现在很多...
    大崔老师阅读 3,329评论 1 2
  • 赵霞1阅读 261评论 0 0
  • 每个人心底 都住着一只怪兽 我们把它 锁在家里 一段时间就独自 拉出来遛遛 也有次 你很久忘记遛 它跟随着你 在你...
    pomoo阅读 377评论 0 0