通过 UIPanGestureRecognizer 传递点击 [英] Pass taps through a UIPanGestureRecognizer
问题描述
我想检测整个屏幕上的滑动,但是,屏幕包含 UIButton
s,如果用户点击这些按钮之一,我希望触发 Touch Up Inside 事件.我在屏幕顶部创建了一个 UIView
,并在其上添加了一个 UIPanGestureRecognizer
以检测滑动,但现在我需要通过该视图传递手势我发现这是轻按而不是轻扫.
I'd like to detect swipe on the entire screen, however, the screen contains UIButton
s, and if the user taps one of these buttons, I want the Touch Up Inside event to be triggered.
I've create a UIView
on the top of my screen, and added a UIPanGestureRecognizer
on it to detect the swipe, but now I need to pass the gesture through that view when I detect that it's a tap rather than a swipe.
我知道如何区分手势,但我不知道如何将其传递给下面的视图.
I know how to differentiate the gestures, but I've no idea on how to pass it to the view below.
有人可以帮忙吗?谢谢!
Can anyone help on that? Thanks!
推荐答案
感谢您的回答.该链接帮助我解决了部分问题.我已将按钮设置为我的gestureRecognizer 视图的子视图,现在我可以从其中一个按钮开始滑动(并继续使用这些按钮).我使用以下代码设法阻止按钮进入向下"状态:
Thanks for your answer. The link helped me to solve part of my problem. I've set the buttons as subviews of my gestureRecognizer view and I can now start a swipe from one of the buttons (and continue to use the buttons as well). I managed to prevent the buttons to go to the "down" state by using the following code :
UIPanGestureRecognizer *swipe = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(swipeDetected:)];
swipe.maximumNumberOfTouches = 1;
swipe.delaysTouchesBegan =YES;
swipe.cancelsTouchesInView = YES;
[self.gestureRecognitionView addGestureRecognizer:swipe];
这篇关于通过 UIPanGestureRecognizer 传递点击的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!