我有一个地图视图,类似于以下方式添加注释:
- (MKAnnotationView *)mapView:(MKMapView *)mapView
viewForAnnotation:(id <MKAnnotation>) annotation
{
MKAnnotationView *annotationView = [[MKPinAnnotationView alloc] initWithAnnotation:annotation
reuseIdentifier:@"MKPinAnnotationView"];
annotationView.canShowCallout = YES;
UIButton *detailButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
[detailButton addTarget:self
action:@selector(handleButtonAction)
forControlEvents:UIControlEventTouchUpInside];
annotationView.rightCalloutAccessoryView = detailButton;
return annotationView;
}
在iOS 7中,这会在呼出框右侧放置一个“i”图标。点击图标会触发委托的mapView:annotationView:calloutAccessoryControlTapped:
和自身的handleButtonAction:
方法。然而,我最近意识到,您也可以在呼出框的任何其他位置进行点击,这两种方法也会被激活。这种情况在使用UIButtonTypeDetailDisclosure
类型的按钮时会发生,但是在使用UIButtonTypeCustom
类型的按钮时似乎不会发生。当没有附件视图时,单击呼出框时也不会触发委托方法。(当然,这种行为并不令人惊讶;令人惊讶的是,如果附件视图是详细信息披露按钮,则无论您单击按钮本身还是仅在呼出框的其他地方单击,这两种方法都会触发。)我想要摆脱呼出框中的按钮——或者至少用显示我自己图像的按钮替换它,而仍然允许用户在呼出框的任何位置进行点击以触发我的操作。这是否可能?我没有看到对应于“呼出框被单击”的MKMapViewDelegate
方法。