Hide text selection handles after action in UIWebView

烈酒焚心 提交于 2019-12-20 08:49:40

问题


I have several custom UIMenuItems that do things with a selection in a UIWebView. After the action has been run on that selection I want to hide the selection handles just as copy: does.

I have tried using window.getSelection().removeAllRanges(); and that works in that window.getSelection() no longer returns anything but the text selection handles stay visible.

Is there a way to remove the selection and the handles with it?

Edit: I don't need it to be a JS solution but I can't loose the state by reloading the webview.


回答1:


Just disable and re-enable the User Interaction:

myWebView.userInteractionEnabled = NO;
myWebView.userInteractionEnabled = YES;



回答2:


you can simply refresh the webview if your data is only text then no body can trace that webview is refreshed

use this code

[webview reload];

i have done this thing in my apps & its work great




回答3:


[_webview becomeFirstResponder]; After your action.

You just need this. I always use this way.



来源:https://stackoverflow.com/questions/3542347/hide-text-selection-handles-after-action-in-uiwebview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!