3

I just have an UICollectionView inside my UIViewController.

I am using SWRevealViewController to open left/right side menu. I can set its panGestureRecognizer to provide full screen panning.

view.addGestureRecognizer(self.revealViewController().panGestureRecognizer())

The following method will provide a panGestureRecognizer suitable to be added to any view in order to perform usual drag and swipe gestures to reveal the rear views. This is usually added to the top bar of a front controller, but it can be added to your frontViewController view or to the reveal controller view to provide full screen panning. By default, the panGestureRecognizer is added to the view containing the front controller view. To keep this default behavior you still need to call this method, just don't add it to any of your views. The default setup allows you to dissable user interactions on your controller views without affecting the recognizer.

My issue is that on a specific cell of my UICollectionView I don't have any spacing on the edges. The cellWidth = collectionView.bounds.size.width AND this cell contains an UICollectionView with horizontal scrolling.

Instead of opening my left/right menu, it just scroll horizontally my UICollectionView.

I would like to handle this scenario:

1: if the panGesture is located within the UICollectionViewCell containing the UICollectionView with horizontal scrolling.

2: detect the gesture location on the horizontal axis, and if it is on the edge of the screen, don't trigger the horizontal scrolling of the UICollectionView but trigger the panGesture to open the menu.

After reading a lot of articles and the official documentation I found this UIScreenEdgePanGestureRecognizer.

But also that this logic should be done by overriding the method shouldReceiveTouch, am I right?

Any hint on how I should implement this ?

EDIT:

After reading the question suggested in the comment, this is what I tried, but it's not working.

let edgePanGesture = UIScreenEdgePanGestureRecognizer()
collectionView.panGestureRecognizer.require(toFail: edgePanGesture)

I set this in my cell containing the horizontal collectionView but it's not working.

I might be missing something, any help?

  • 1
    This post may help you: https://stackoverflow.com/questions/21794778/prevent-uiscrollviews-uipangesturerecognizer-from-blocking-uiscreenedgepangestu – River2202 Oct 05 '18 at 13:13
  • This is an helpful post, however it's not working (check edit) –  Oct 05 '18 at 13:23
  • The only way I can think is kinda "hacking" solution. You can a dummy transparent view on the sidemenu side of a small width and over the UICollectionView to be able to receive the gesture. I know it will cover that part on your UICollectionView, but maybe is not a problem for a width of, let's say 8 points – Andreas777 Oct 08 '18 at 12:39
  • I tried to add some content Insent at the left and right of my horizontal UICollectionView so that I can see the "parent view" and thus, detect my pan gesture. But I really need my horizontal CollectionView to have the full width of my screen (I have a background image, it will be awful the other way) –  Oct 08 '18 at 12:43
  • But it will be transparent and over the UICollectionView. It will not hide anything. Only if you try to scroll to the edge it will open the sidemenu. – Andreas777 Oct 08 '18 at 12:46
  • You understand what I mean? – Andreas777 Oct 08 '18 at 12:52
  • Yes, I will try it and give you feedback. –  Oct 08 '18 at 13:07

0 Answers0