在我的 iPhone 应用程序的一个 UIViewControllers 上,我连接了一个 UIPanGestureRecognizer,以便当用户向左或向右滑动时,应用程序前进或返回一个屏幕。然而,问题是当用户在屏幕上点击(而不是滑动)时,它仍然会前进。我怎样才能阻止这种情况发生。我在下面粘贴了相关代码:
-(void) addGestureRecognizer
{
UIPanGestureRecognizer *pan;
pan = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(swipeRecognized:)];
[pan setMinimumNumberOfTouches:1];
[self.view addGestureRecognizer:pan];
}
-(void) swipeRecognized: (UIPanGestureRecognizer *) recognizer
{
if(recognizer.state != UIGestureRecognizerStateBegan) return;
CGPoint velocity = [recognizer velocityInView:self.view];
if(velocity.x > 0)
{
[self.navigationController popViewControllerAnimated:YES];
}
else
{
@try
{
[self performSegueWithIdentifier:NEXT_STEP_SEGUE sender:self];
}
@catch (NSException *exception)
{
//Silently die...muhaha
}
}
}