gpt4 book ai didi

objective-c - 如何阻止 UIPanGestureRecognizer 识别点击

转载 作者:行者123 更新时间:2023-11-29 13:26:47 25 4
gpt4 key购买 nike

在我的 iPhone 应用程序的一个 UIViewController 上,我附加了一个 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
}
}
}

最佳答案

我建议使用 UISwipeGestureRecognizer 进行滑动。您使用平底锅有什么特别的原因吗?

使用 UISwipeGestureRecognizer,您可以指定它应该识别哪个方向的手势。

使用适当的手势对您的用户也更好。这样,他们就会有宾至如归的感觉 :)

关于objective-c - 如何阻止 UIPanGestureRecognizer 识别点击,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12942601/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com