如何将ContentView()分配给NSWINDOW? 我使用可可来创建一个窗口。我想在该窗口中显示ContentView()。 导入可可 @主要的 appdelegate类:nsobject,nsapplicationdelegate { var windowx:nswindow! ...

问题描述 投票:0回答:1

创建AppDelegate

swift macos swiftui cocoa
1个回答
0
投票
    aptach AppDelegate到您的SwiftUi应用程序。您也需要创建至少1个场景。为了确保不会在应用程序启动中显示此场景,您需要创建设置场景
import SwiftUI @main struct FocusitoApp: App { @NSApplicationDelegateAdaptor(AppDelegate.self) var appDelegate var body: some Scene { Settings { SettingsView() } .commands { ReplaceMenus() } } }

    在function openmainwnd()您需要创建WND实例并分配您的视图
windowX.contentView = NSHostingView(rootView: ContentView())
    
最新问题
© www.soinside.com 2019 - 2025. All rights reserved.