经过一些测试。我发现以下方法最适合我。对于 MacCatalyst 应用程序。
步骤:
将以下代码添加到 AppDelegate。因此删除默认帮助。
override func buildMenu(with builder: UIMenuBuilder) {
super.buildMenu(with: builder)
builder.remove(menu: .help)
}
将以下选择器添加到 AppDelegate。这将提供一个指向您的帮助网站的链接。
@IBAction func openHelp() {
UIApplication.shared.open(URL(string: "https://www.legolas.me/blankbook-english")!)
}
最后,将以下代码添加到 buildMenu 函数中。在 builder.remove 之后。
let helpCommand = UIKeyCommand(input: "W", modifierFlags: [.command], action: #selector(openHelp))
helpCommand.title = "Blankbook's Guide"
let helpMenu = UIMenu(title: "Blankbook's Guide", image: nil, identifier: UIMenu.Identifier("guide"), options: .displayInline, children: [helpCommand])
builder.insertChild(helpMenu, atStartOfMenu: .application)
这是最终结果: