如何在UITEXTVIEW中禁用共享和查找
我试图隐藏文本菜单,除了复制
和两个原始菜单。
我使用以下代码来抑制几乎所有内容...但是不知何故,我无法隐藏查找
和share
(以及spell
)和会说
,添加了6月10日)。
override func canPerformAction(_ action: Selector, withSender sender: Any?) -> Bool {
if action == Selector(("_lookup:")) ||
action == Selector(("_share:"))
{
return false
} else if
action == #selector(UIResponderStandardEditActions.copy(_:)) ||
action == #selector(copyAll(_:)) ||
action == #selector(lookUpWord (_:))
{
return true
} else {
return false
}
}
我调试了代码,并目睹了当查找
和共享
进入if-Statement时,该函数确实会返回false。但是,以某种方式没有在菜单上反映出来。
我如何确保禁用查找
,<代码>共享,spell
和speak
?
-----更新----
修改为扩展 但是某种程度上仍然无法按照我想要的方式工作。菜单在此扩展中没有反映代码...
extension UITextView {
open override func canPerformAction(_ action: Selector, withSender sender: Any?) -> Bool {
if action == Selector(("_lookup:")) ||
action == Selector(("_share:"))
{
return false
} else if
action == #selector(UIResponderStandardEditActions.copy(_:)) ||
action == #selector(ViewController.copyAll(_:)) ||
action == #selector(ViewController.lookUpWord (_:))
{
return true
} else {
return false
}
}
}
I am trying to hide the text menus except for copy
and two original menus.
I used the following code to suppress pretty much everything... but somehow, I can not hide look up
and share
(as well as Spell
and Speak
, added Jun 10).
override func canPerformAction(_ action: Selector, withSender sender: Any?) -> Bool {
if action == Selector(("_lookup:")) ||
action == Selector(("_share:"))
{
return false
} else if
action == #selector(UIResponderStandardEditActions.copy(_:)) ||
action == #selector(copyAll(_:)) ||
action == #selector(lookUpWord (_:))
{
return true
} else {
return false
}
}
I debugged the code and witnessed that the function does return false when lookup
and share
went into the if-statement. But, somehow this is not reflected on the menu.
How can I make sure to disable look up
, share
, Spell
, and Speak
?
----- updated ----
Modified as extension
But somehow still not working in the way I want. The menu does not reflect the code in this extension...
extension UITextView {
open override func canPerformAction(_ action: Selector, withSender sender: Any?) -> Bool {
if action == Selector(("_lookup:")) ||
action == Selector(("_share:"))
{
return false
} else if
action == #selector(UIResponderStandardEditActions.copy(_:)) ||
action == #selector(ViewController.copyAll(_:)) ||
action == #selector(ViewController.lookUpWord (_:))
{
return true
} else {
return false
}
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用所需的自定义实现来创建UITEXTVIEW的子类。
要禁用查找,您需要使用
selector((“ _define:”))
。这是一个禁用
共享
&amp;的示例。查找
选项:并将其用作:
编辑:
,如果要找到特定操作的
选择器
,请尝试以下方式:选择行动将打印相关的动作:
或者您可以放置一个断点,然后查看所呼叫的“动作”。
You can create subclass of UITextView with the custom implementation you want.
To disable lookup, you need to use
Selector (("_define:"))
.Here is an example which disables
Share
&Lookup
option :And use this as:
Edit:
And if you want to find the
Selector
for the Specific actions, Try this way:Select the action and this will print the associated action:
Or you can place a breakpoint and see what you're getting called with for "action".