可触摸图像作为注释标注?

时间:2012-02-26 10:24:31

标签: objective-c mkannotation mapkit

我尝试使用BarButton,但这是错误的:

CGSize thumbSize = CGSizeMake(30.0, 30.0);
UIImageView *annotationThumbnail = [[UIImageView alloc] initWithImage:[((Sight *)annotation).thumbnail imageToFitSize:thumbSize method:MGImageResizeScale]];
UIBarButtonItem *annotationButton = [[UIBarButtonItem alloc] initWithCustomView:annotationThumbnail];

annotationView.leftCalloutAccessoryView = annotationButton;

1 个答案:

答案 0 :(得分:2)

UIBarButtonItem不是UIView的子类,因此在需要视图的地方使用UIBarButtonItem的实例是行不通的。相反,您可以像这样使用annotationThumbnail

annotationView.leftCalloutAccessoryView = annotationThumbnail;

如果您改为使用UIControl子类,例如UIButton,如果有人点击了标注附件,地图的委托将收到-mapView:annotationView:calloutAccessoryControlTapped:消息:

UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[button setBackgroundImage:someImage forState:UIControlStateNormal];
button.frame = someRect;
annotationView.leftCalloutAccessoryView = button;