2

I am seeing behavior in my UICollectionView that I don't understand, and would like to prevent.

I have a UICollectionView with a bunch of custom cells in it. It horizontally scrolls, and it has paging enabled. I have allowsSelection, allowsMultipleSelection, and scrollsToTop = NO.

I have single & double tap UITapGestureRecognizers on each cell.

I have the shouldSelectItemAtIndexPath delegate method returning NO, as I'm managing the actions taken on the cells through these gesture recognizers.

Here's what happens- When I tap the last cell that is furthest to the right in the collection view, it scrolls backwards (to the left) automatically, takes the item that I just selected off screen and is no longer visible, and THEN fires the gesture recognizer handler.

If I look at myCollectionView.visibleCells inside my gesture recognizer selector, I see that the cell is not contained in there, as it's been scrolled off screen.

This only happens when paging is enabled- if I turn it off and tap the last item, everything works as expected and no automatic scrolling backwards occurrs.

Why does this happen and how can I prevent it??? I'd like the same behaviour to take place with and without paging enabled, but can't right now.

How can I prevent UICollectionView automatically scrolling before gesture recognizer selector is called?

EDIT

If I subclass my UICollectionViewFlowLayout and override:

-(CGSize) collectionViewContentSize {
    return CGSizeMake(10000, CGRectGetHeight(self.collectionView.frame));
}

set to an arbitrarily high number, the automatic scrolling backwards does not occur. Looks like this is happening due to contentSize?

barfoon
  • 25,436
  • 24
  • 88
  • 136
  • 1
    I seem to be running into the same issue - did you ever find a fix for your problem? It appears it only happens if the page size is less than 50% of the collectionView.frame.width... – opfeffer Sep 08 '14 at 23:53
  • Yeah, noticed the same thing as well. Didn't end up spending too much more time on it as we went with a non-paged solution. If you find out anything I'll take a look. Cheers – barfoon Sep 10 '14 at 00:03
  • Did you find solution to fix this issue? – imike Sep 17 '15 at 04:02

0 Answers0