您必须实现 UIGestureRecognizerDelegate 方法:
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer;
并将您的控制器添加为手势识别器的代表。然后,当两个手势识别器响应一个手势时,将调用此方法,您可以在此处为您的应用实现所需的逻辑。
在控制器的接口声明中,您必须键入:
@interface testcViewController () <UIGestureRecognizerDelegate>
然后,在创建手势识别器时:
UISwipeGestureRecognizer *swipe = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipe)];
swipe.direction = UISwipeGestureRecognizerDirectionDown;
swipe.delegate = self;
[self.view addGestureRecognizer:swipe];
然后,最后,将此方法添加到控制器:
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer
{
BOOL shouldInteract = NO;
//Here you decide whether or not the two recognizers whould interact.
return shouldInteract;
}
编辑
您还可以实施
- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer;
在这里,检测您是否已经呈现了子视图,并阻止您想要的任何手势。