Swift:如何单击按钮打开新的 window?

Swift: How can I open a new window clicking a button?

我是这种编程语言的新手,我想创建一个应用程序,当我单击按钮时,它会打开 window 并提供一些信息,但我不知道该怎么做。

我没有使用情节提要,因为我读到对于专业编程来说这些是行不通的。

我不想要 iOS,我想要 OS X。

大家好!

这很简单。您可以按照以下步骤操作:

import Cocoa

@NSApplicationMain
class AppDelegate: NSObject, NSApplicationDelegate {
    @IBOutlet weak var window: NSWindow!
    let myNewWindow = NSWindow(contentRect: NSMakeRect(0,0,640,480), styleMask: NSBorderlessWindowMask, backing: NSBackingStoreType.Buffered, defer: false)
    //        NSBorderlessWindowMask  = 0,
    //        NSTitledWindowMask  = 1 << 0,
    //        NSClosableWindowMask  = 1 << 1,
    //        NSMiniaturizableWindowMask  = 1 << 2,
    //        NSResizableWindowMask  = 1 << 3,
    //        NSTexturedBackgroundWindowMask  = 1 << 8
    func applicationDidFinishLaunching(aNotification: NSNotification) {
        // Insert code here to initialize your application

    }
    func applicationWillTerminate(aNotification: NSNotification) {
        // Insert code here to tear down your application
    }
    @IBAction func btnNewWindow(sender: AnyObject) {
        myNewWindow.opaque = false
        myNewWindow.movableByWindowBackground = true
        myNewWindow.backgroundColor = NSColor(hue: 0, saturation: 1, brightness: 0, alpha: 0.7)
        myNewWindow.makeKeyAndOrderFront(nil)
    }
}