Use interactivepopgesturerecognizer with CollectionView with horizontal scroll when navigation bar is hidden
Asked Answered
T

2

7

i'm trying to use the interactivepopgesturerecognizer to go back in a view in which i have also a UICollectionView with horizontal scrolling, and the problem is that in the frame of the collection view the swipe to go back doesn't work, but works when the touch begin out of the frame of the collection view, this is an example of my view:

| ---> here works
|-----------
|
| ---> This is the collection view and doesn't swipe to go back
|
|-----------
| ---> here works

how i can solve the problem?

EDIT: i realized that this problem occurs only when in the pushed view the nav bar is hidden, and when is hidden the swipe to go back doesn't work in all view not only in the collection view, and to make it work i need to add this line:

[self.navigationController.interactivePopGestureRecognizer setDelegate:nil];

in the main view, but in this way i can't swipe to go back in the collection view. i have created a simple test to check the problem:

https://www.dropbox.com/s/c7ueyrcmm2x1m5w/TestSwipe.zip?dl=0

Tropho answered 21/1, 2015 at 20:44 Comment(2)
Can't reproduce, you have to start from the left edge to swipe, maybe you could share some code.Prussianism
i'm sorry, i have edit the questionTropho
S
29

Add this line of code to your viewDidLoad method in your SecondViewController

[self.collectionView.panGestureRecognizer requireGestureRecognizerToFail:self.navigationController.interactivePopGestureRecognizer];

This essentially tells the collection view's gesture recognizer that it needs to wait for the interactive pop recognizer to fail before proceeding, forcing the interactive pop to be prioritized.

Sisneros answered 24/1, 2015 at 11:30 Comment(0)
N
8

Swift 3 (add to viewDidLoad):

    if let interactivePopGestureRecognizer = navigationController?.interactivePopGestureRecognizer {
        collectionView.panGestureRecognizer.require(toFail: interactivePopGestureRecognizer)
    }
Nomadize answered 2/5, 2017 at 18:41 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.