iPhone模拟器向右滑动可以,但向左滑动不行?
我正在尝试在 UIScrollView 上向左和向右滑动。然而,看起来向左滑动在 iPhone 模拟器中不起作用,尽管向右滑动可以。我错过了什么步骤吗?
- (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; self.scrollView.multipleTouchEnabled = YES; UISwipeGestureRecognizer *swipe = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipe:)]; swipe.delaysTouchesBegan = YES; swipe.numberOfTouchesRequired = 2; [self.scrollView addGestureRecognizer:swipe]; [swipe release]; } - (void)handleSwipe:(UISwipeGestureRecognizer *)recognizer { if (recognizer.direction == UISwipeGestureRecognizerDirectionLeft) { } else if (recognizer.direction == UISwipeGestureRecognizerDirectionRight) { } }
I'm trying to use swipe left and right on a UIScrollView. However it looks like swipe left does not work in iPhone simulator even though swipe right does. Did I miss any step?
- (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; self.scrollView.multipleTouchEnabled = YES; UISwipeGestureRecognizer *swipe = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipe:)]; swipe.delaysTouchesBegan = YES; swipe.numberOfTouchesRequired = 2; [self.scrollView addGestureRecognizer:swipe]; [swipe release]; } - (void)handleSwipe:(UISwipeGestureRecognizer *)recognizer { if (recognizer.direction == UISwipeGestureRecognizerDirectionLeft) { } else if (recognizer.direction == UISwipeGestureRecognizerDirectionRight) { } }
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
使用以下内容:
Use Following:
您的“handleSwipe”代码实际上是正确的。您需要两个 UISwipeGestureRecognizer,但您可以将它们都指向同一处理程序,其中包含“IF”语句。
Your 'handleSwipe' code is actually correct. You need two UISwipeGestureRecognizers but you can point them both to the same handler, containing your 'IF' statement.
您可以创建一个手势识别器来处理左右滑动(甚至所有方向 -!):
所有方向:
You can create one gesture recognizer that handles both left and right swipe (or even all directions-!):
All directions: