you need to implement these functions in your controller, check these links for reference Disable entire UIMenuController edit menu in WKWebView
WKWebView and UIMenuController
override func viewDidLoad() {
super.viewDidLoad()
NotificationCenter.default.addObserver(
self,
selector: #selector(uiMenuViewControllerDidShowMenu),
name: NSNotification.Name.UIMenuControllerDidShowMenu,
object: nil)
}
deinit
deinit {
NotificationCenter.default.removeObserver(
self,
name: NSNotification.Name.UIMenuControllerDidShowMenu,
object: nil)
}
func uiMenuViewControllerDidShowMenu() {
if longPress {
let menuController = UIMenuController.shared
menuController.setMenuVisible(false, animated: false)
menuController.update() //You can only call this and it will still work as expected but i also call setMenuVisible just to make sure.
}
}
class WebView: WKWebView {
override func willOpenMenu(_ menu: NSMenu, with event: NSEvent) {
if let reloadMenuItem = menu.item(withTitle: "Reload") {
menu.removeItem(reloadMenuItem)
}
}
}