嗯,快速浏览一下文档会发现你做的工作比你需要的要多:
"direction 允许的滑动方向。
@property(nonatomic) UISwipeGestureRecognizerDirection direction
UISwipeGestureRecognizerDirection
讨论 您可以通过使用按位或操作数指定多个常量来指定多个方向。默认方向是UISwipeGestureRecognizerDirectionRight
。"
也就是说,您可以执行以下操作,而不是使用两个 UISwipeGestureRecognizers:
UISwipeGestureRecognizer *swipeGesture = [[UISwipeGestureRecognizer alloc]
initWithTarget:self action:@selector(handleSwipeGesture:)];
swipeGesture.direction = UISwipeGestureRecognizerDirectionRight | UISwipeGestureRecognizerDirectionLeft;
在您的操作方法中:
-(IBAction)handleSwipeGesture:(UISwipeGestureRecognizer*)sender
{
if (sender.direction == UISwipeGestureRecognizerDirectionLeft) {
//do left action
} else {
//do right action
}
}
更简单,更不容易发生冲突。