ios百度地图怎么防止点击空白地方气泡消失

2025-04-30 17:17:30
推荐回答(1个)
回答1:

-(BMKAnnotationView *)mapView:(BMKMapView *)mapView viewForAnnotation:(id)annotation{
static NSString * showUserInfoPinIdentifier = @"myAnnotation";
// 如果传入的annotation不是自定义大头针视图,直接返回nil,使用地图默认的方法绘制大头针
// 如果是自定义视图,则设置大头针属性
if (![annotation isKindOfClass:[AQAnnotationObject class]]) {
return nil;
}
AQAnnotationObject* ann=(AQAnnotationObject*)annotation;
BMKAnnotationView *view = [mapView dequeueReusableAnnotationViewWithIdentifier:showUserInfoPinIdentifier];
// 如果没有找到可重用的大头针视图,实例化新的
if (view == nil) {
view = [[BMKAnnotationView alloc]initWithAnnotation:annotation reuseIdentifier:showUserInfoPinIdentifier];
view.canShowCallout = YES;
}
// 设置大头针视图属性
// 1) 如果大头针视图是从缓冲池取出的,必须要重新设置位置
NSLog(@"%@",NSStringFromCGRect(view.frame));
[view setAnnotation:annotation];
// 2) 设置大头针图像
view.frame=CGRectMake(0, 0, 27, 36);
view.backgroundColor=[UIColor redColor];
UIImageView* imageView=[[UIImageView alloc]initWithFrame:view.bounds];
imageView.image=[UIImage imageNamed:@"1_female"];
if (![ann.dic[@"gender"]isEqual:[NSNull null]]) {
if ([ann.dic[@"gender"]integerValue]) {
imageView.image=[UIImage imageNamed:@"1_male"];
}
}
[view addSubview:imageView];
AQPaoPao* paopao=[[AQPaoPao alloc]init];
UIView* backView=[[UIView alloc]initWithFrame:CGRectMake(0, 0, 100, 100)];
backView.backgroundColor=[UIColor yellowColor];
BMKActionPaopaoView* paopaoView=[[BMKActionPaopaoView alloc]initWithCustomView:paopao];
paopaoView.frame=CGRectMake(0, 0, 142, 77);
view.paopaoView=paopaoView;
return view;

}

能正常显示标注,但是点击标注没有弹出泡泡
没有走以下的代理方法

-(void)mapView:(BMKMapView *)mapView didSelectAnnotationView:(BMKAnnotationView *)view{
NSLog(@"按了");
}