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

      2. <small id='T46nv'></small><noframes id='T46nv'>

      3. <tfoot id='T46nv'></tfoot>
          <bdo id='T46nv'></bdo><ul id='T46nv'></ul>

        如何获取 UIWebView 中选定文本的坐标(CGRect)?

        How to get coordinates (CGRect) for the selected text in UIWebView?(如何获取 UIWebView 中选定文本的坐标(CGRect)?)

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

              <tbody id='WQgJ6'></tbody>

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

              <tfoot id='WQgJ6'></tfoot>
                  本文介绍了如何获取 UIWebView 中选定文本的坐标(CGRect)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我有简单的 UIWebView 和加载的 html.我想显示指向所选文本的 PopoverView.我可以获取 UIMenuController 的 menuFrame 并使用它的 rect,但结果在屏幕的角落并不像我需要的那样准确.我可以计算屏幕大小并获取 menuFrame rect,然后我可以假设可以在哪里找到选择,但我想确切地知道所选文本在哪里.一般可以吗?

                  I have simple UIWebView with loaded html. I want to show the PopoverView pointed to the selected text. I can get the menuFrame of the UIMenuController and use its rect, but the result isn't as accurate at the corners of the screen as I need. I can calculate the screen size and get menuFrame rect and then I can suppose where the selection may be found, but I want exactly know where is the selected text. Is it generally possible?

                  推荐答案

                  您可以在所选文本的范围对象上使用 javascript 函数 getBoundingClientRect().我就是这样做的:

                  You can use the javascript function getBoundingClientRect() on the range object of the selected text. This is how I do it:

                  function getRectForSelectedText() {
                      var selection = window.getSelection(); 
                      var range = selection.getRangeAt(0); 
                      var rect = range.getBoundingClientRect(); 
                      return "{{" + rect.left + "," + rect.top + "}, {" + rect.width + "," + rect.height + "}}";
                  }
                  

                  在 UIWebView 的一个类别中,你可以这样使用它:

                  and in a category on UIWebView, you could use it like such:

                  - (CGRect)rectForSelectedText{
                      CGRect selectedTextFrame = CGRectFromString([self stringByEvaluatingJavaScriptFromString:@"getRectForSelectedText()"]);
                      return selectedTextFrame;
                  }
                  

                  这篇关于如何获取 UIWebView 中选定文本的坐标(CGRect)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  EAAccessory/EASession teardown during background(EAAccessory/EASession 在后台拆除)
                  Getting an NSArray of a single attribute from an NSArray(从 NSArray 获取单个属性的 NSArray)
                  ImageIO: lt;ERRORgt; JPEG Corrupt JPEG data: premature end of data segment iphone - how to catch this?(ImageIO:lt;错误gt;JPEG 损坏的 JPEG 数据:iphone 数据段过早结束 - 如何捕捉到这个?)
                  How to get indexPath.row of tableView which is currently being displayed?(如何获取当前正在显示的 tableView 的 indexPath.row?)
                  Xcode iOS organizer submit to app store yields quot;The archive is invalidquot; error(Xcode iOS 管理器提交到应用商店产生“存档无效;错误)
                  MFMessageComposeViewController alloc returns nil(MFMessageComposeViewController alloc 返回 nil)

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

                          <tbody id='Fayhh'></tbody>

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

                        <tfoot id='Fayhh'></tfoot>

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