Prevent UIScrollView's UIPanGestureRecognizer from blocking UIScreenEdgePanGestureRecognizer

与世无争的帅哥 提交于 2019-12-02 19:28:09

Unfortunately, creating this behavior can be a real P*** i* t** A**.

Fortunately, creating this behavior is possible using the UIGestureRecognizer Delegate even if you can't access one GestureRecognizer directly.

-(BOOL)gestureRecognizer:shouldRequireFailureOfGestureRecognizer:
-(BOOL)gestureRecognizer:shouldRecognizeSimultaneouslyWithGestureRecognizer:
-(BOOL)gestureRecognizer:shouldBeRequiredToFailByGestureRecognizer: 

The second parameter ('otherGestureRecognizer') passed in the delegate methods holds the UIScrollView's PanGestureRecognizer (or private Apple - subclasses) when your gestureRecognizer 'collides' with the scrollView's.

So simply set your UIScreenEdgePanGestureRecognizer's delegate to reply to the delegate methods.

The naming of these two methods is very suboptimal and to be honest, i don't really know what the correct return values for your case are.

I just had this problem yesterday and i solved it by brutal trial & error.

Im my case, returning NO from both shouldRequireToFail and shouldBeRequiredToFail methods and YES from the simultaneous-method solved my problem.

Note: Returning NO from both methods changed the behavior compared to not 
even implementing the methods at all. Even though the documentation says 
the default return value is NO.

However, ANY GestureRecognizer behavior can be achieved by using the delegate methods. But as i said above, the naming of the methods is just very confusing. + there is as much as NO useful documentation for these methods.

This can be done without having to set the screen pan gesture's delegate to your view controller.

[scrollView.panGestureRecognizer requireGestureRecognizerToFail:screenPanGesture];
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!