WKWebView not rendering correctly in iOS 10

后端 未结 5 760
攒了一身酷
攒了一身酷 2020-12-15 03:45

I have WKWebView inside the UITableViewCell. The web view load request and then after finished loading, I\'ll resize the web view height to be equal to its content height, t

5条回答
  •  感动是毒
    2020-12-15 04:30

    I have the same problem - add a WKWebView to a UITableViewCell, and I solved this problem by these steps:

    1.Create a UITextView instance and add it to UITableView's superview(UIViewControllew.view) 2.implement codes in scrollViewDidScroll like this:
    - (void)scrollViewDidScroll:(UIScrollView *)scrollView
    {
        [self.xxtextView becomeFirstResponder];
        [self.xxtextView resignFirstResponder];
    }
    

    These codes may cause increased cpu performance overhead, you can fix it by some way such us use a temp variable as threshold value.

    I don't think this is a perfect solve method, but it works for me.


    Eventually I realized that textview becomeFirstResponder just led the webview layout again, so you can just fix it like this:

    CGFloat tempOffset = 0;
    
    - (void)scrollViewDidScroll:(UIScrollView *)scrollView
    {
        if (!tempOffset || ABS(scrollView.contentOffset.y - tempOffset) > ScreenHeight/2)
        {
            [self.wkWebView setNeedsLayout];
            tempOffset = scrollView.contentOffset.y;
        }
    }
    

提交回复
热议问题