The problem is that if you try to set the contentOffset of your collection view to viewWillAppear, the collection view has not yet displayed its elements. Therefore, self.collectionView.contentSize is still {0,0}. The solution is to ask the collection view layout for the size of the content.
Also, you'll want to make sure that you only set contentOffset when contentSize is above the bounds of your collection view.
The complete solution looks like this:
- (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; CGSize contentSize = [self.collectionView.collectionViewLayout collectionViewContentSize]; if (contentSize.height > self.collectionView.bounds.size.height) { CGPoint targetContentOffset = CGPointMake(0.0f, contentSize.height - self.collectionView.bounds.size.height); [self.collectionView setContentOffset:targetContentOffset]; } }
awolf
source share