我以这种方式在uiviewconroller中显示UIMenuController:
在我班上:
override open func canBecomeFirstResponder() -> Bool {
return true
}
open override func canPerformAction(_ action: Selector, withSender sender: Any) -> Bool {
//here I check for my custom action, else return false
return false
}
然后显示我使用:
//Make this as first responder
self.becomeFirstResponder()
///Build menu
let menu = UIMenuController.shared
///Set item and anchor point, and showit
menu.menuItems = itemsToAdd
menu.setTargetRect(CGRect(x: 0, y: 5, width: bubbleNode.view.bounds.size.width, height: bubbleNode.view.bounds.size.height), in: bubbleImageNode.view)
menu.setMenuVisible(true, animated: true)
问题在于我在设备中显示我的自定义项目,还有:“拼写,说话,斑点句子,ecc ......”我该如何禁用它?
答案 0 :(得分:0)
覆盖canPerformAction并为每个特定操作处理它。它非常适合我。
override func canPerformAction(_ action: Selector, withSender sender: Any?) -> Bool {
var canPerform = super.canPerformAction(action, withSender: sender)
if (action == "your action to restrict") {
canPerform = false
}
return canPerform
}
答案 1 :(得分:0)
好的,问题是"辅助功能"选项"说出选择"在我的设备中,如果我禁用它,我只会看到自定义项目,但在其他应用程序中,我只看到启用了此选项的自定义项目!
答案 2 :(得分:0)
class TextViewWithCopyAction: UITextView {
override func canPerformAction(_ action: Selector, withSender sender: Any?) -> Bool {
if action == #selector(copy(_:)){
return true
} else {
return false
}
}
}
使用:
let textView: TextViewWithCopyAction = {
let textView = TextViewWithCopyAction()
textView.backgroundColor = .white
return textView
}()
答案 3 :(得分:-1)
如果您在UIMenuController
中看到来自设备的说选项,请转到:
设置->辅助功能->语音->语音
选择并禁用它。自动讲话选项将从菜单中删除。