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 UITapGestureRecognizer
s 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
?