iOS7 Webview initial scroll position under Navigation bar

后端 未结 8 2607
[愿得一人]
[愿得一人] 2021-02-18 22:50

I have a webview which is scrolling as desired underneath a navigation bar.

However, when I first load the controller, the page loaded in the webview is scrolled so that

相关标签:
8条回答
  • 2021-02-18 23:31

    Rick's answer is correct except the top value should be negative, this is what worked for me!

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

    I used -44, if you don't have status bar on the top you should use -64.

    0 讨论(0)
  • 2021-02-18 23:33

    The way I solved this issue is with the webViewDidFinishLoad delegate callback. In the callback method for the web view I set do all the work to make the web view's scroll view look correct.

    [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];
    
    0 讨论(0)
提交回复
热议问题