So I have been trying to get this simple behavior working on my iPhone app now for a while. I have a nav bar at the top and a tab bar at the bottom. I am loading all of my c
I've encountered with the same problem.
And found simple fix.
The culprit is UIViewController
's property automaticallyAdjustsScrollViewInsets
. UIViewController
reference says:
Default value is
YES
, which allows the view controller to adjust its scroll view insets in response to the screen areas consumed by the status bar, navigation bar, and toolbar or tab bar.
It means that UIViewController
adds that top gap to UIWebView
's scroll view even if you properly set up webview frame or add autolayout constraints. To overcome this behaviour just
Set to
NO
if you want to manage scroll view inset adjustments yourself, such as when there is more than one scroll view in the view hierarchy.
"manage scroll view inset adjustments your self" in our context means that we won't add any insets ;)
same issue with any scroll view, i.e. Blank space at top of UITextView in iOS 10 https://stackoverflow.com/search?q=automaticallyAdjustsScrollViewInsets
This issue has also resurfaced with iPhone X.
With iOS 11, UIScrollView now has the property contentInsetAdjustmentBehavior.
webview.scrollView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
can correct this issue.