在我的地图上,我有rightCalloutAccessoryView
个UIButtonTypeDetailDisclosure
。我想检测用户是否点击注释的中心或UIButtonTypeDetailDisclosure
。
例如,如果他点击中心:执行名为XYZ的segue,如果UIButtonTypeDetailDisclosure上的点击:执行一个名为ABC的序列。
这是我的代码。问题是UIButtonTypeDetailDisclosure
和注释执行名为" infoDetail"的相同segue。我尝试使用rightCalloutAccessoryView
和leftCalloutAccessoryView
上的标记进行不同配置,以检测哪一个被点按,但如何在右侧使用UIButtonTypeDetailDisclosure
检测注释的中心?
- (void)mapView:(MKMapView *)mapView didAddAnnotationViews:(NSArray *)views {
MKAnnotationView *aView;
for (aView in views) {
if (![aView.annotation isKindOfClass:[MKUserLocation class]]) {
MKAnnotationView* annotationView = aView;
annotationView.rightCalloutAccessoryView = [UIButton buttonWithType: UIButtonTypeDetailDisclosure];
annotationView.rightCalloutAccessoryView.tag = 1;
annotationView.leftCalloutAccessoryView = [UIButton buttonWithType:UIButtonTypeContactAdd];
annotationView.leftCalloutAccessoryView.tag = 2;
}
} }
- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control {
if ([control tag] == 1) {
// Right Accessory Button Tapped
[self performSegueWithIdentifier:@"infoDetail" sender:self];
} else if ([control tag] == 2) {
// Left Accessory Button Tapped
[self performSegueWithIdentifier:@"contactDetail" sender:self];
} }
答案 0 :(得分:0)
我在mapView上使用带触摸手势的自定义按钮制作了这个。我不认为这是处理你的项目的干净方式,但它对我有用。我用自定义注释视图SMCalloutView做了这个。 https://github.com/nfarina/calloutview
UIButton *leftDisclosure = [UIButton buttonWithType:UIButtonTypeCustom];
leftDisclosure.backgroundColor = [UIColor clearColor];
topDisclosure.frame = theframeYouWant;
[topDisclosure addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(disclosureTapped:)]];
annotationView.rightAccessoryView = topDisclosure;
这很棘手,我希望它会对你有所帮助。