iOS-百度地图自定义气泡
IOS百度地图自定义大头针和气泡
重点是定义了一个全局变量来取气泡的数据模型:
static int paopaoIndex = 0;
- (BMKAnnotationView *)mapView:(BMKMapView *)view viewForAnnotation:(id <BMKAnnotation>)annotation
{
// 生成重用标示identifier
NSString *AnnotationViewID = @"xidanMark";
// 检查是否有重用的缓存
BMKAnnotationView* annotationView = [view dequeueReusableAnnotationViewWithIdentifier:AnnotationViewID];
// 缓存没有命中,自己构造一个,一般首次添加annotation代码会运行到此处
if (annotationView == nil) {
annotationView = [[BMKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:AnnotationViewID];
// ((BMKPinAnnotationView*)annotationView).pinColor = BMKPinAnnotationColorRed;
[self setUpPinStyleWithImageName:@"xyRedPin" view:((BMKPinAnnotationView*)annotationView)];
// 设置重天上掉下的效果(annotation)
((BMKPinAnnotationView*)annotationView).animatesDrop = YES;
}
// 设置位置
annotationView.centerOffset = CGPointMake(0, -(annotationView.frame.size.height * 0.5));
annotationView.annotation = annotation;
// 单击弹出泡泡,弹出泡泡前提annotation必须实现title属性
annotationView.canShowCallout = YES;
// 设置是否可以拖拽
annotationView.draggable = NO;
annotationView.paopaoView=[self customPaoPaoView:paopaoIndex];
paopaoIndex ++;
return annotationView;
}
- (BMKActionPaopaoView *)customPaoPaoView:(int)index{
XYShopListModel *shopListModel = (XYShopListModel *)_resultList[index];
//1.自定义内容气泡
UIView *paoView=[[UIView alloc]initWithFrame:CGRectMake(0, 0, 300, 44)];
paoView.backgroundColor=[UIColor clearColor];
//2.背景图片
UIImageView *background = [[UIImageView alloc] initWithFrame:paoView.frame];
background.image = [UIImage imageNamed:@"paopaoBackground"];
background.layer.cornerRadius=8;
background.layer.masksToBounds=YES;
[paoView addSubview:background];
//3.导航按钮
UIButton *navigationBtn = [self customNavigationBtn];
[paoView addSubview:navigationBtn];
//6.添加向右图标
UIImageView *rightIcon = [UIImageView new];
rightIcon.image = [UIImage imageNamed:@"dropdownmune"];
[background addSubview:rightIcon];
rightIcon.sd_layout
.rightEqualToView(background)
.topSpaceToView(background, 15)
.widthIs(rightIconwidth)
.heightIs(10);
//详情holderView
UIView *detailHolderView = [self detailHolderViewWith:shopListModel];
[paoView addSubview:detailHolderView];
[detailHolderView setYh_x:navigationBtn_width];
[detailHolderView setYh_y:0];
//detailHolderView是动态变的,所以要刷新一下底部的view新的宽
CGFloat allWidth = navigationBtn_width + rightIconwidth + detailHolderView.frame.size.width;
[paoView setYh_width: allWidth];
[background setYh_width:allWidth];
BMKActionPaopaoView *paopao=[[BMKActionPaopaoView alloc]initWithCustomView:paoView];
return paopao;
}
网友评论