iOS:是否可以在MKMapView中添加三击手势识别器?

时间:2013-05-15 17:04:13

标签: ios mkmapview uigesturerecognizer

我有一个MKMapView,在双击时放大(默认行为)。我想在地图视图中添加三击手势识别器,再次缩小到某个初始缩放级别 问题是内置双击识别器首先触发。为了延迟这一点,必须以某种方式访问​​双击识别器,但至少在iOS6中,view属性gestureRecognizers不包含地图视图的双击识别器。
那么,是否可以以某种方式延迟双击识别器以便允许三抽头识别器首先触发?

1 个答案:

答案 0 :(得分:6)

查看requireGestureRecognizerToFail类中的实例方法UIGestureRecognizer

http://developer.apple.com/library/ios/documentation/uikit/reference/UIGestureRecognizer_Class/Reference/Reference.html#//apple_ref/occ/instm/UIGestureRecognizer/requireGestureRecognizerToFail

  

在接收器和另一个手势识别器之间创建依赖关系。

例如:

[doubleTap requireGestureRecognizerToFail:tripleTap];

更新

经过一段时间的讨论之后,我得到了这样的工作(假设你有MKMapView名为mapView):

UITapGestureRecognizer *tripleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTripleTap:)];
tripleTap.numberOfTapsRequired = 3;
[mapView.subviews[0] addGestureRecognizer:tripleTap];

UIView *tempMapView = mapView.subviews[0];
NSArray *mapGestures = tempMapView.gestureRecognizers;
UITapGestureRecognizer *tempMapDoubleTap = mapGestures[0];
[tempMapDoubleTap requireGestureRecognizerToFail:tripleTap];
NSLog(@"%@", mapGestures);

Triple Tap Selector:

- (void)handleTripleTap:(UIGestureRecognizer *)gestureRecognizer {
    NSLog(@"Triple Tap Detected..");
}

现在双击仍会缩放MKMapView并且三次点击成功执行handleTripleTap而不进行缩放。