• <tfoot id='bmSNK'></tfoot>
      <bdo id='bmSNK'></bdo><ul id='bmSNK'></ul>

    <small id='bmSNK'></small><noframes id='bmSNK'>

  • <i id='bmSNK'><tr id='bmSNK'><dt id='bmSNK'><q id='bmSNK'><span id='bmSNK'><b id='bmSNK'><form id='bmSNK'><ins id='bmSNK'></ins><ul id='bmSNK'></ul><sub id='bmSNK'></sub></form><legend id='bmSNK'></legend><bdo id='bmSNK'><pre id='bmSNK'><center id='bmSNK'></center></pre></bdo></b><th id='bmSNK'></th></span></q></dt></tr></i><div id='bmSNK'><tfoot id='bmSNK'></tfoot><dl id='bmSNK'><fieldset id='bmSNK'></fieldset></dl></div>

      1. <legend id='bmSNK'><style id='bmSNK'><dir id='bmSNK'><q id='bmSNK'></q></dir></style></legend>

        iOS WKWebView 检测何时到达底部

        时间:2023-10-22
        • <tfoot id='YSsZ4'></tfoot>
        • <small id='YSsZ4'></small><noframes id='YSsZ4'>

              <bdo id='YSsZ4'></bdo><ul id='YSsZ4'></ul>

                  <legend id='YSsZ4'><style id='YSsZ4'><dir id='YSsZ4'><q id='YSsZ4'></q></dir></style></legend>
                    <tbody id='YSsZ4'></tbody>
                1. <i id='YSsZ4'><tr id='YSsZ4'><dt id='YSsZ4'><q id='YSsZ4'><span id='YSsZ4'><b id='YSsZ4'><form id='YSsZ4'><ins id='YSsZ4'></ins><ul id='YSsZ4'></ul><sub id='YSsZ4'></sub></form><legend id='YSsZ4'></legend><bdo id='YSsZ4'><pre id='YSsZ4'><center id='YSsZ4'></center></pre></bdo></b><th id='YSsZ4'></th></span></q></dt></tr></i><div id='YSsZ4'><tfoot id='YSsZ4'></tfoot><dl id='YSsZ4'><fieldset id='YSsZ4'></fieldset></dl></div>

                  本文介绍了iOS WKWebView 检测何时到达底部的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我有一个从 UIViewView 到 WKWebView 的迁移问题,检测到使用 WKWebView 时滚动视图到达底部.在 WKWebView 之前,我使用 UIScrollViewDelegate 检测用户是否通过滚动到 WebView 结束来查看所有内容.如果他这样做了,则启用确认"按钮.iPhone - 知道 UIScrollView 是到达顶部还是底部

                  I have a migration issue from UIViewView to WKWebView, detecting the Scroll View reached bottom when using WKWebView. Prior to WKWebView I used the UIScrollViewDelegate detecting wether the User had seen all of the content by scrolling till the end of the WebView. If he did, the "confirm" button was enabled. iPhone - knowing if a UIScrollView reached the top or bottom

                  现在使用 WKWebView 这不再起作用了.我猜原因是,当使用 WKWebView 并加载 html 字符串时,它会缩小视图以完全显示内容.所以我必须通过将视口附加到 html 字符串来设置视口.这以与 UIWebView 相同的方式显示内容,提供 html 字符串,而不设置视口.

                  Now with WKWebView this doesn't work anymore. I guess the reason is, when using a WKWebView and load a html string, it scales the view down for full visiblity of the content. So I had to set the viewport by appending it to the html string. This displays the content in the same way, the UIWebView did, providing the html string, without setting a viewport.

                  但是现在加载时的 UIScrollViewDelegate 总是告诉底部已经到达.我猜,WKWebView 加载 html,以完全可见性缩放它,scrollViewDelegate 识别,内容是完全可见的,之后视口进入并向上缩放页面,因此需要垂直滚动来显示全部内容.但是此时,我的确认"按钮已经启用.

                  But now the UIScrollViewDelegate on load always tells that the bottom already reached. I guess, that the WKWebView loads the html, scales it at full visiblity, the scrollViewDelegate recognizes, that the content was fully visible, after that the viewport comes in and scales the page up, so a vertical scroll is needed to display the full content. But at this time, my "confirm" button is already enabled.

                  代码片段

                  override func scrollViewDidScroll(_ scrollView: UIScrollView){
                      let scrollViewHeight = scrollView.frame.size.height;
                      let scrollContentSizeHeight = scrollView.contentSize.height;
                      let scrollOffset = scrollView.contentOffset.y;
                      if (scrollOffset + scrollViewHeight == scrollContentSizeHeight)
                      {
                          self.confirmButton.isEnabled = true; 
                      }
                  }
                  

                  使用 WKWebView,scrollContentSizeHeight 在加载时始终与 scrollViewHeight 相同,但在 scrollViewDidScroll 委托函数调用多次(不滚动)后,scrollContentSizeHeight 大于实际大小的 scrollViewHeight.

                  With WKWebView, the scrollContentSizeHeight always is the same as scrollViewHeight on load, but after the scrollViewDidScroll delegate function invokes mulitple times (without scrolling) the scrollContentSizeHeight is larger than the scrollViewHeight at real size.

                  推荐答案

                  但是现在加载的 UIScrollViewDelegate 总是告诉底部已经到达.

                  But now the UIScrollViewDelegate on load always tells that the bottom already reached.

                  在特定情况下的问题是 UIScrollView 委托在 WKWebView 完全加载之前被调用.

                  The issue in the particular case is UIScrollView delegate is getting called before the WKWebView is loaded completely.

                  取一个私有实例变量,检查URL是否加载完毕.

                  Take one private instance variable to check if the URL is loaded completely or not.

                  var isURLLoaded = false
                  

                  确认 WKWebView 委托给您的 viewController.

                  Confirm WKWebView delegates to your viewController.

                  webView.scrollView.delegate = self
                  webView.navigationDelegate = self
                  

                  并覆盖这些委托方法:

                  func scrollViewDidScroll(_ scrollView: UIScrollView) {
                  
                      if isURLLoaded {
                          if scrollView.contentOffset.y >= (scrollView.contentSize.height - scrollView.frame.size.height) {
                              confirmButton.isEnabled = true
                          } else if scrollView.contentOffset.y < scrollView.contentSize.height {
                              confirmButton.isEnabled = false
                          }
                      }
                  }
                  
                  func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) {
                  
                      isURLLoaded = true
                  }
                  

                  这篇关于iOS WKWebView 检测何时到达底部的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:忽略 NSURLErrorDomain 错误 -999 在 UIWebView 中不起作用 下一篇:在 UIWebView 上显示背景图像

                  相关文章

                  <tfoot id='Gt8M2'></tfoot>
                  1. <i id='Gt8M2'><tr id='Gt8M2'><dt id='Gt8M2'><q id='Gt8M2'><span id='Gt8M2'><b id='Gt8M2'><form id='Gt8M2'><ins id='Gt8M2'></ins><ul id='Gt8M2'></ul><sub id='Gt8M2'></sub></form><legend id='Gt8M2'></legend><bdo id='Gt8M2'><pre id='Gt8M2'><center id='Gt8M2'></center></pre></bdo></b><th id='Gt8M2'></th></span></q></dt></tr></i><div id='Gt8M2'><tfoot id='Gt8M2'></tfoot><dl id='Gt8M2'><fieldset id='Gt8M2'></fieldset></dl></div>

                    <small id='Gt8M2'></small><noframes id='Gt8M2'>

                    <legend id='Gt8M2'><style id='Gt8M2'><dir id='Gt8M2'><q id='Gt8M2'></q></dir></style></legend>
                      <bdo id='Gt8M2'></bdo><ul id='Gt8M2'></ul>