UISwipeGestureRecognizer无法执行一些时间

时间:2014-05-21 10:48:14

标签: ios objective-c ipad uiswipegesturerecognizer

在我的应用程序中,我添加了UISwipeGestureRecognizer以在viewControllers之间导航,但有时无法对滑动手势执行操作。我只是在父viewDidLoad的{​​{1}}中添加了向左滑动和向右滑动手势,因为我想在我的所有孩子viewController中添加相同内容。

viewControllers

我还添加了日志,以检查是否错过滑动,如下所示。

//Adding swipe gesture recognizers
UISwipeGestureRecognizer *swipeLeftGesture=[[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(rightNavigationButtonTapped)];
swipeLeftGesture.delegate = self;
[self.view addGestureRecognizer:swipeLeftGesture];
swipeLeftGesture.direction = UISwipeGestureRecognizerDirectionLeft;

UISwipeGestureRecognizer *swipeRightGesture=[[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(leftNavigationButtonTapped)];
swipeRightGesture.delegate = self;
[self.view addGestureRecognizer:swipeRightGesture];
swipeRightGesture.direction = UISwipeGestureRecognizerDirectionRight;

在我的情况下,当滑动工作正常时,这是日志:

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
NSLog(@"touched for event %@", event.class);
}

-(BOOL)gestureRecognizer:(UIGestureRecognizer *)gesture
 shouldRequireFailureOfGestureRecognizer:(UIGestureRecognizer *)otherGesture {
NSLog(@"gesture failed %@", otherGesture.class);
return YES;
}

-(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:      (UITouch *)touch{
 NSLog(@"touch %@", gestureRecognizer.class);
 return YES;
 }

当滑动操作不正确时,这是日志:

<Warning>: touch UISwipeGestureRecognizer
<Warning>: touch UISwipeGestureRecognizer
<Warning>: gesture failed _UISystemGestureGateGestureRecognizer
<Warning>: gesture failed _UISystemGestureGateGestureRecognizer
<Warning>: gesture failed UISwipeGestureRecognizer
<Warning>: gesture failed _UISystemGestureGateGestureRecognizer
<Warning>: gesture failed _UISystemGestureGateGestureRecognizer
<Warning>: touched for event UITouchesEvent

目前我无法理解我案件中发生的实际问题以及可能存在的问题。如果你知道为什么会出现这个问题,请告诉我。

1 个答案:

答案 0 :(得分:0)

您是否尝试过返回NO -(BOOL)gestureRecognizer:(UIGestureRecognizer *)gesture shouldRequireFailureOfGestureRecognizer:(UIGestureRecognizer *)otherGesture?因为这是默认行为,这个简单的UISwipGestureRecognizer设置对我有用。