iOS7 UIWebView - Set content starting position below navigation bar

南楼画角 提交于 2019-12-04 04:15:31

问题


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:


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 !



来源:https://stackoverflow.com/questions/22404291/ios7-uiwebview-set-content-starting-position-below-navigation-bar

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!