简体   繁体   English

使用 swift 启动主窗口

[英]Start a main window using swift

I'm kind of new in swift, but I'm ' stuck ' in something.我是 swift 的新手,但我“在”某事上。

I know C, Java, C++, PHP, etc...我知道 C、Java、C++、PHP 等...

I'm trying to compose an multi-windowed App (Mac OS application using Cocoa), using swift.我正在尝试使用 swift 编写一个多窗口应用程序(使用 Cocoa 的 Mac OS 应用程序)。 I can already do it, but my problem is when I close the main window.我已经可以做到了,但我的问题是当我关闭窗口时。 If I close my main window, when I try to add a child to it, I will get an error or the new window just does not open.如果我关闭我的主窗口,当我尝试向它添加一个子窗口时,我会收到一个错误,或者新窗口没有打开。

I have this:我有这个:

class SmallWindow: NSViewController {

    @IBOutlet var window: NSWindow! //Window inside the .xib file

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do view setup here.
    }

}

I already tried the above using NSWindowController and NSWindow .我已经使用NSWindowControllerNSWindow尝试了上述方法。

var smallwin = SmallWindow()
smallwin.window.makeKeyAndOrderFront(self) 
//already tried with smallwin.window too

I am wondering how to programmatically start a new window.我想知道如何以编程方式启动一个新窗口。 Am I missing some steps?我错过了一些步骤吗?

@IBOutlet var window: NSWindow!
@IBOutlet var smallwin : SmallWindow!

func applicationDidFinishLaunching(aNotification: NSNotification) {

    smallwin = SmallWindow()
    window.addChildWindow(smallwin.window, ordered: NSWindowOrderingMode.Above)

}

You probably don't need a child window.您可能不需要窗口。 You just need a window.你只需要一个窗口。

To put a new window on the screen, you need to do three things:要在屏幕上放置一个新窗口,您需要做三件事:

  1. Create the window, either programmatically or by loading a nib.以编程方式或通过加载笔尖来创建窗口。

  2. Send an order-in message to the window.向窗口发送订购信息。 Usually you want to send makeKeyAndOrderFront or orderFront .通常你想发送makeKeyAndOrderFrontorderFront See “Opening and Closing Windows” in the Window Programming Guide .请参阅Window Programming Guide中的“打开和关闭 Windows”

  3. Keep a strong reference to the window.保持对窗口的强烈参考。 The system doesn't necessarily keep a strong reference to an on-screen window.系统不一定保持对屏幕窗口的强引用。 If the window is deallocated, it will remove itself from the screen.如果窗口被释放,它会从屏幕上移除自己。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在OSX的Swift的主窗口中设置自定义视图 - Set custom view in main window in Swift on OSX 使用Swift的iOS:“ _ main”,引用自:主可执行文件的隐式输入/启动 - iOS with Swift: “_main”, referenced from: implicit entry/start for main executable Swift:使用 start with 过滤字符串 - Swift: Filter string by using start with 使用swift ui进行macOS开发时看不到预览,也看不到我的应用程序的主窗口(运行时) - Unable to see preview and unable to see the main window of my app (when running) while using swift ui for macOS developement Swift:如何将触控栏控件链接到主窗口控件 - Swift: How to link Touch Bar controls to main window controls 使用 Swift 调整主屏幕亮度 - Adjust the main screen brightness using Swift Xcode 11.2.1 - Swift 5 - 无法将主故事板“Main”更改为另一个故事板“Start” - Xcode 11.2.1 - Swift 5 - Can't change main storyboard "Main" to another storyboard "Start" 使用spritekit swift在swift中创建游戏主菜单 - Create a main menu for game in swift using spritekit swift 使用swift 4的整个窗口的视觉效果视图 - Visual effect View for entire window using swift 4 迅速,无法使用JSQMessagesViewController重新加载聊天窗口 - Swift, unable to reload chat window using JSQMessagesViewController
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM