[英]Swipe Gesture Recogniser not triggering?
I have a page view controller with five view controllers that get displayed. 我有一个页面视图控制器,其中包含五个显示的视图控制器。
I have tried adding these swipe gestures but they are not getting called? 我尝试添加这些滑动手势,但没有被调用?
UISwipeGestureRecognizer *swipeGestureRight = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleRightSwipe:)];
swipeGestureRight.numberOfTouchesRequired = 1;
swipeGestureRight.direction = (UISwipeGestureRecognizerDirectionRight);
[self.scrollView addGestureRecognizer:swipeGestureRight];
UISwipeGestureRecognizer *swipeGestureLeft = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleLeftSwipe:)];
swipeGestureLeft.numberOfTouchesRequired = 1;
swipeGestureLeft.direction = (UISwipeGestureRecognizerDirectionLeft);
[self.scrollView addGestureRecognizer:swipeGestureLeft];
Why arn't these being triggered and what can I do about it? 为什么不触发这些,我该怎么办? My goal is to detect what direction the user swipes the page view controller.
我的目标是检测用户向哪个方向滑动页面视图控制器。
add gesture to self.view 向self.view添加手势
[self.view addGestureRecognizer:swipeGestureRight];
I hope it will work 我希望它能起作用
Try this 尝试这个
Set the delegate of your UIGestureRecognizer
and 设置您的
UIGestureRecognizer
的代表,并
Implement shouldRecognizeSimultaneouslyWithGestureRecognizer
: 工具应使用
shouldRecognizeSimultaneouslyWithGestureRecognizer
:
-(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer{ return YES; }
Implement shouldReceiveTouch
: 实现
shouldReceiveTouch
:
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch { return YES; }
Hope this helps. 希望这可以帮助。 Let me know if you still face the issue.
让我知道您是否仍然面对这个问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.