在iOS Mobile Safari和/或UIWebView中控制文本选择行为? [英] Control text selection behavior in iOS Mobile Safari and/or UIWebView?

查看:393
本文介绍了在iOS Mobile Safari和/或UIWebView中控制文本选择行为?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含多个段落的长HTML文档。当我尝试在iOS上的Mobile Safari或UIWebView中选择文本时,会发生以下情况:

I have a long HTML document that contains multiple paragraphs. When I try to select the text either in Mobile Safari on iOS or in a UIWebView, the following happens:


  1. 首先,级精度我的选择。

  2. 然后,当我选择更多,精度下降到两行文本,最终到整个段落。没有办法结束我的文本选择正是我想要的地方。

当我将CSS contentEditable 属性设置为 true 时,我保留字符级精度,但键盘也出现了,这当然是我不想要的。

When I set the CSS contentEditable property to true, I retain the character-level precision, but the keyboard also shows up, which of course I don't want.

无论我选择的文本有多长,都有办法保留字符级选择精度吗?

Is there any way to retain the character-level selection precision no matter how long the text is that I am selecting?

推荐答案

iOS 8的 WKWebView 可能能够解决这个问题。 WKWebViewConfiguration 有一个名为 selectionGranularity 的属性。注释如下:

iOS 8's WKWebView might be able to solve this problem. WKWebViewConfiguration has a property called selectionGranularity. The comment reads:


用户可以在Web视图中交互式选择
内容的粒度级别。可能的值在
WKSelectionGranularity中描述。默认值为
WKSelectionGranularityDynamic。

The level of granularity with which the user can interactively select content in the web view. Possible values are described in WKSelectionGranularity. The default value is WKSelectionGranularityDynamic.

两个可能的值之一是 WKSelectionGranularityCharacter 。注释说:

One of the two possible values is WKSelectionGranularityCharacter. The comment says:


选择端点可以放置在任何字符边界。

Selection endpoints can be placed at any character boundary.

我还没试过,但听起来很有前途。

I have not tried it yet, but it sounds very promising!

更新7/6/15 :看起来不那么容易: WKWebView中的文本选择:WKSelectionGranularityCharacter

Update 7/6/15: It looks like it's not that easy: Text Selection in WKWebView: WKSelectionGranularityCharacter

更新7/10/15 :当仔细调查iOS Kindle应用程序时,您可以看到他们已经重新实现了原生文本选择JavaScript,因为他们不能做原生文本选择行为他们想要的方式。我很确定他们必须试过一切,然后才决定重新实现它。

Update 7/10/15: When you closely investigate the iOS Kindle app, you can see that they have re-implemented "native" text selection in JavaScript because they couldn't make native text selection behave the way they wanted to. I'm pretty sure they must have tried everything else before they decided to re-implement it.

这篇关于在iOS Mobile Safari和/或UIWebView中控制文本选择行为?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆