【发布时间】:2020-03-18 23:27:42
【问题描述】:
更改 Mac Catalyst 的“关于应用程序”窗口? 是怎么做到的?
【问题讨论】:
标签: swift xcode menuitem mac-catalyst
更改 Mac Catalyst 的“关于应用程序”窗口? 是怎么做到的?
【问题讨论】:
标签: swift xcode menuitem mac-catalyst
类似这样的:
#if targetEnvironment(macCatalyst)
extension AppDelegate {
override func buildMenu(with builder: UIMenuBuilder) {
guard builder.system == .main else { return }
// override about button
builder.replaceChildren(ofMenu: .about) { (oldChildren) -> [UIMenuElement] in
let menuElement = oldChildren.first
if let uiCommand = menuElement as? UICommand {
let aboutUICommand = UICommand(title: uiCommand.title,
action: #selector(aboutApp(_:)))
return [aboutUICommand]
} else {
return oldChildren
}
}
}
override func canPerformAction(_ action: Selector, withSender sender: Any?) -> Bool {
return super.canPerformAction(action, withSender: sender)
}
override func target(forAction action: Selector, withSender sender: Any?) -> Any? {
if action == #selector(aboutApp) {
return self
} else {
return nil
}
}
@objc func aboutApp(_ selector: Any?) {
guard let aboutTVC = AboutViewController.createInstance() else { return; }
rootViewController?.present(aboutTVC, animated: true, completion: nil)
}
}
#endif
【讨论】: