【问题标题】:Custom "About Application" window with Mac Catalyst使用 Mac Catalyst 自定义“关于应用程序”窗口
【发布时间】:2020-03-18 23:27:42
【问题描述】:

更改 Mac Catalyst 的“关于应用程序”窗口? 是怎么做到的?

【问题讨论】:

    标签: swift xcode menuitem mac-catalyst


    【解决方案1】:

    类似这样的:

    #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
    

    【讨论】:

    • 非常感谢!我确实设法将“关于”菜单项链接到模式视图。是否也可以将“关于”视图作为单独的窗口(“应用程序窗口之外”)?关于窗口的标准与应用菜单是分开的。
    • 可以,但是你需要为你的应用开启多窗口并使用uiscenedelegate来管理窗口
    猜你喜欢
    • 2019-11-29
    • 1970-01-01
    • 2021-12-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-02-21
    • 1970-01-01
    • 2020-06-15
    相关资源
    最近更新 更多