在我的地图应用程序中,我想要显示一个带有图像的彩色背景圆形,而不是显示一个标记针。背景圆的颜色(在下面的图片中是绿色系的)是动态的。它将如下图所示:
我创建了 TCircleView,它在“drawRect”中绘制颜色。
为了显示类似的注释,我创建了 TCircleView 和 UIImageView 对象,并将它们添加到 MKAnnotationView 对象中。它看起来很好,如预期的那样可见。
但是它不允许检测点击/触摸以显示弹出窗口。
我正在使用以下代码:
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation {
if ([annotation isKindOfClass:[MKPointAnnotation class]]) {
return nil;
}
static NSString *annotationIdentifier = @"StickerPin";
MKAnnotationView *annotationView = (MKAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:annotationIdentifier];
if (!annotationView) {
annotationView = [[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:annotationIdentifier];
annotationView.canShowCallout = YES;
}
TCircleView* circleView = [[TCircleView alloc] init];
circleView.green = [postObj[@"severity"] floatValue]; //dynamic value coming from server
UIImageView* imgView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"Piano"]];
CGRect r = imgView.frame;
r.size.height = r.size.width = 60;
imgView.frame = r;
circleView.frame = r;
[annotationView addSubview:circleView];
[annotationView addSubview:imgView];
return annotationView;
}
无法显示标注或甚至调用委托"didSelectAnnotationView:",如何在地图上显示自定义视图作为标注?