6

I was able to create a unified toolbar in Mac Catalyst with this in the SceneDelegate.swift:

// Use a UIHostingController as window root view controller.
if let windowScene = scene as? UIWindowScene {
    let window = UIWindow(windowScene: windowScene)
    window.rootViewController = UIHostingController(rootView: contentView)
    // hide the titlebar
    windowScene.titlebar?.toolbar = NSToolbar()
    windowScene.titlebar?.titleVisibility = .hidden
    ...
}

But I want to make the toolbar transparent like in this example: https://lukakerr.github.io/swift/nswindow-styles#11-transparent-toolbar-without-seperator

Is this even possible in Mac Catalyst?

4

3 回答 3

7

Yes, this is possible in Mac Catalyst. In your SceneDelegate.swift file, set both toolbar and title visibility to false and .hidden respectively.

func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
    guard let windowScene = (scene as? UIWindowScene) else { return }

    #if targetEnvironment(macCatalyst)
    windowScene.titlebar?.toolbar?.isVisible = false
    windowScene.titlebar?.titleVisibility = .hidden
    #endif
}
于 2019-12-22T18:19:00.493 回答
2

覆盖 func viewDidAppear(_ animated: Bool) { super.viewDidAppear(animated)

    #if targetEnvironment(macCatalyst)
    
    if let titlebar = self.view.window?.windowScene?.titlebar {
            titlebar.titleVisibility = .hidden
            titlebar.toolbar = nil
        }
    #endif
    
    
}
于 2020-12-13T11:08:24.280 回答
0

这是一个类似的解决方案:

func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {

guard let windowScene = (scene as? UIWindowScene) else { return }

#if targetEnvironment(macCatalyst) //check target
if let titlebar = windowScene.titlebar {
    titlebar.titleVisibility = .hidden
    titlebar.toolbar = nil
}
#endif

}
于 2020-02-20T21:18:53.517 回答