MKPinAnnotationView rightCalloutAccessoryView不会在iOS7上发送calloutAccessoryControlTapped

Ner*_*tel 4 ios mkmapviewdelegate ios7

我正在尝试将我的一个应用程序更新到iOS7.问题是,在我MKMapView,当我点击一个引脚时,它显示了Callout,但是当点击rightCalloutAccessoryView它时,它不再向委托发送任何回调.因此,我无法推动细节视图.

它在iOS6上运行良好,在iOS7上不再适用.

这是相关的代码:

- (MKAnnotationView *) mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation {
    if ([annotation isKindOfClass:[MKUserLocation class]]) {
        return nil;
    }
    NSString * annotationIdentifier = nil;
    if ([annotation isKindOfClass:VPStation.class]) {
        annotationIdentifier = @"stationAnnotationIdentifier";
    }
    if (!annotation) {
        return nil;
    }
    MKPinAnnotationView * annotationView = [(MKPinAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:annotationIdentifier] retain];
    if(annotationView == nil) {
        annotationView = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:annotationIdentifier];
        annotationView.canShowCallout = YES;
        annotationView.rightCalloutAccessoryView = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
        annotationView.image = [UIImage imageNamed:@"MyAnnotationPin"];
        annotationView.centerOffset = CGPointMake(-10.0f, 0.0f);
    }
    annotationView.annotation = annotation;

    return [annotationView autorelease];
}

- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control {
    if ([view.annotation isKindOfClass:VPStation.class]) {
        VPTotalDetailViewController * detailVC = [[VPTotalDetailViewController alloc] initWithStation:(VPStation *)view.annotation
                                                                                      andUserLocation:self.mapView.userLocation.coordinate];
        [self.navigationController pushViewController:detailVC animated:YES];
        [detailVC release];
    }
}
Run Code Online (Sandbox Code Playgroud)

根据MKAnnotationView班级参考:

如果您指定的视图也是UIControl类的后代,则可以使用地图视图的委托在轻触控件时接收通知.如果它不是从UIControl下降,则您的视图负责处理其范围内的任何触摸事件.

有没有什么比使用我自己的UIView子类来获取触摸并推送detailViewController 更简单?我应该等苹果来修复这个错误吗?我相信这是一个bug,不是吗?

提前致谢

Ner*_*tel 12

好吧,这里的问题是我有一个UIGestureRecognizer设置MKMapView(为了它的价值,它是一个自定义识别器,但我不相信这会改变任何东西)和这个手势识别器消耗触摸,然后不转发给calloutAccessoryControl.请注意,这种行为改变了 iOS6的和iOS7之间.修复很简单,我添加了我的控制器作为识别器的代表(它不是之前)并实现了该UIGestureRecognizerDelegate方法:

#pragma mark - UIGestureRecognizerDelegate
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch {
    if ([touch.view isKindOfClass:[UIControl class]]) {
        return NO;
    }
    return YES;
}
Run Code Online (Sandbox Code Playgroud)