ios UIScrollView have a bad default contentOffset - swift ios UIScrollView have a bad default contentOffset - swift swift swift

ios UIScrollView have a bad default contentOffset - swift


It's probably an issue with the view insets.

On your XIB/Storyboard for your view controller, make sure to uncheck the Adjust Scroll View Insets

uncheck the Adjust Scroll View Insets

or in your code add self.automaticallyAdjustsScrollViewInsets = false


Swift 4.2+

scrollView.contentInsetAdjustmentBehavior = .never


I found the explanation on this website:

http://www.codelord.net/2013/10/18/adapting-scroll-views-to-ios-7/

Handling navigation bar on top of our scroll view

The iOS 7 view of course comes with the new look where scroll views go under the navigation bar for a nice effect. One can change the scroll view’s contentInset manually to cover for the portion of it that is being overlapped at the top, but doing so manually is tedious and not fun. I was very thrilled to discover handling it should come at no cost if my ViewController has automaticallyAdjustsScrollViewInsets set to YES.

This didn’t work for me out of the box since it turns out for the magic to happen the scroll view has to be the first subview of your ViewController’s UIView. I had to reorder my subviews and then the magic started rolling.