【发布时间】:2020-06-24 02:11:49
【问题描述】:
我想在 WKWebView 中使用自定义 UIMenuController。
首先,我想摆脱默认菜单(复制、查找、分享),但由于某种原因我不知道,但它并没有消失。
override open func canPerformAction(_ action: Selector, withSender sender: Any?) -> Bool {
switch action {
case #selector(highlightHandler):
return true
default:
return false
}
}
func enableCustomMenu() {
let memo = UIMenuItem(title: "메모", action: #selector(highlightHandler))
UIMenuController.shared.menuItems = [memo]
UIMenuController.shared.update()
}
@objc func highlightHandler(sender: UIMenuItem) { }
我尝试使用上面的代码删除默认的 menuItems 并添加名为“메모”的自定义 menuItems,但它没有。
如何只显示我想要的名为“메모”的项目?
【问题讨论】:
-
您确定正在调用
canPerformAction方法吗? -
试试
override func canPerformAction(_ action: Selector, withSender sender: Any?) -> Bool { [#selector(highlightHandler)].contains(action) } -
不需要调用
update()。显示您拨打的位置UIMenuController.shared.showMenu(... -
@Leo Dabus 谢谢。但结果还是一样。