3
votes

I have a UIViewController designed in a Storyboard (IB) as follows :

  • UIWebView stretched to fill the entire canvas
  • UIWebView has AutoLayout constraints to pin all 4 sides to the edges of the superview
  • UIViewController has all 'Extend Edges' options ticked so UIWebView sits underneath navigation bar
  • UIViewController has 'Adjust Scroll View Insets' unticked
  • UIViewController is loaded within a UINavigationController

What I want to happen when the VC loads is for the top of the UIWebView content to be positioned immediately below the navigation bar, and allow the user to scroll the content up the screen under the navigation bar (same as how the Dropbox app works when viewing PDFs). I have tried various attempts at this including using :

[webView.scrollView setContentInset:UIEdgeInsetsMake(64, 0, 0, 0)];
[webView.scrollView setScrollIndicatorInsets:UIEdgeInsetsMake(64, 0, 0, 0)];
[webView.scrollView scrollRectToVisible:CGRectMake(0, 0, 1, 1) animated:NO];

but I can't get it working - I just end up with the content starting at the top of the screen, underneath the navigation bar. I'm wondering if AutoLayout is preventing this working?

1
You need to change the frame/bounds of your webView at the time of loading the page and using ScrollView Delegatewhen the scroll starts you need to change the orgin.y value of webview for performing scrolls. It might work.Vishnu

1 Answers

3
votes

I had the same issue and fixed it. The solution is pretty simple:

Go to the storyboard, select the view controller which contains your UIWebView and open the Attributes Inspector. Here, you'll see the title "Extend Edges", just uncheck the box "Under Top Bars" and I will work !