0

I have a collectionView with some cells in it. On top of each cell i have a button, so when I press the button the view switches to another controller.

My problem now is, that when I touch the cell and try to scroll, it doesn't.
(Because of the button on top of it)

For the same issue in UIScrollView there's this method:

override func touchesShouldCancel(in view: UIView) -> Bool {
    // Makes the scrollView scrollable when there's a button on top.
    return true
}

I also tried this method instead:

func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
    print("Nothing")
}

And nothing happens.

How can i fix this ?

Sam
  • 79
  • 1
  • 7

3 Answers3

0

Try this:

func viewDidLayoutSubviews() {

   super.viewDidLayoutSubviews()
   self.scroller.isScrollEnabled = true
}

Based on the answer from Mark Kennedy, here: UIButton inside UIScrollView disables scrolling

VSMelo
  • 355
  • 1
  • 5
0

In Button tap method check if CollectionView is Scrolling or not. By Like this

if collectionView.isDragging || collectionView.isDecelerating {
 //`Don't go to Another View Controller`
}

Give a try.

jay patel
  • 238
  • 2
  • 14
-1

In your viewDidLoad() method of your ViewController set collectionView.canCancelContentTouches = true. I hope it will fix your issue.

Umair Aamir
  • 1,624
  • 16
  • 26