I have a UICollectionView
and two subclasses of UICollectionViewFlowLayout
. When a cell is selected, I call setCollectionViewLayout:animated:
to switch between the layouts. After the transition is done, the selected cell is centered, which is fine.
Can the same centering behavior be done without making the cell actually selected? I've tried to call setContentOffset:animated:
in different methods without any success. Alternatively, can I specify a self defined contentOffset
for the layout to be displayed?
To be more clear, I'd like to have something like this without modifying a cell's selected
property:
EDIT #1
This is what I already have:
[self.collectionView selectItemAtIndexPath:indexPath animated:NO scrollPosition:UICollectionViewScrollPositionNone];
[self.collectionView setCollectionViewLayout:layout animated:YES];
Looks fine: https://www.dropbox.com/s/9u6cnwwdbe9vss0/17249646-0.mov
But if I skip selectItemAtIndexPath
:
[self.collectionView setCollectionViewLayout:layout animated:YES];
[self.collectionView scrollRectToVisible:targetFrame animated:YES];
This is not that fine (kind of waving animation): https://www.dropbox.com/s/s3u2eqq16tmex1v/17249646-1.mov