Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS 11: UICollectionView: when appearing, scrolling happens

when my UIViewController appears with a UICollectionView inside, the content scrolls up a little bit, when appearing.

I implemented scrollViewDidScroll: and I'm logging the contentOffset.y:

-20.000000
-20.000000
0.000000
0.000000

This only happens on iOS 11 (simulator and device), not on iOS 10 or iOS 9. Anyone else experiencing this?

EDIT VERY WEIRD thing: this only happens when viewDidLoad is NOT called, so e.g. when the UIViewController already exists and it is popped onto again, but not when first showing that UIViewController...

like image 823
swalkner Avatar asked Aug 24 '17 21:08

swalkner


1 Answers

In iOS 11, contentInset.top can be added in UIScrollView and subclasses (UICollectionView, UITableView) while status bar, navigationBar or other content appear in your view hierarchy.

This inset come from new adjustedContentInset property. (doc : adjustedContentInset)

To remove this extra inset, set content inset adjustment on your scrollView to never :

[self.myScrollView setContentInsetAdjustmentBehavior:UIScrollViewContentInsetAdjustmentNever];

More info in the WWDC17 video : Updating Your App for iOS 11 at 19'

like image 170
vmeyer Avatar answered Oct 18 '22 23:10

vmeyer