iOS7 Webview initial scroll position under Navigation bar

后端 未结 8 2627
[愿得一人]
[愿得一人] 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条回答
  •  旧时难觅i
    2021-02-18 23:21

    For a more general version of @Puran's answer, rather than hardwiring 44 or 64, get it from the topLayoutGuide. Also, if you load multiple times, you only need to change these values once:

    UIEdgeInsets insets = self.myWebView.scrollView.contentInset;
    if ( UIEdgeInsetsEqualToEdgeInsets(insets, UIEdgeInsetsZero)) {
        insets.top = -self.topLayoutGuide.length;
        [self.myWebView.scrollView setContentInset:insets];
        [self.myWebView.scrollView setScrollIndicatorInsets:insets];
        [self.myWebView.scrollView scrollRectToVisible:CGRectMake(0, 0, 1, 1) animated:NO];
    }
    

提交回复
热议问题