以正确的方式对NSWindow进行分类

时间:2016-06-14 15:00:46

标签: swift macos cocoa

我正在尝试添加类似的NSWindow:

customWindow = NSWindow.init(contentRect: rect, styleMask: styleMask, backing: NSBackingStoreType.Buffered, defer: false)
customWindow?.backgroundColor = NSColor(calibratedHue: 0, saturation: 1.0, brightness: 0, alpha: 0.3)
customWindow?.ignoresMouseEvents = true
customWindow?.level = Int(CGWindowLevelForKey(.MaximumWindowLevelKey))
customWindow?.makeKeyAndOrderFront(customWindow)

它显示它应该,但我想继承它。

class Screen: NSWindow {

    init() {
        let screen = NSScreen.mainScreen()
        let frame = NSMakeRect(0, 0, (screen?.frame.size.width)!, (screen?.frame.size.height)!)
        let styleMask = NSBorderlessWindowMask
        let rect = NSWindow.contentRectForFrameRect(frame, styleMask: styleMask)

        super.init(contentRect: rect, styleMask: styleMask, backing: .Buffered, defer: false)

        self.styleMask = styleMask
        self.backingType = NSBackingStoreType.Buffered
        self.setFrame(rect, display: true)  
        self.backgroundColor = NSColor(calibratedHue: 0.5, saturation: 1.0, brightness: 0, alpha: 0.6)
        self.ignoresMouseEvents = true
        self.level =  Int(CGWindowLevelForKey(.MaximumWindowLevelKey))

    }
}

我试着像这样添加它:

let win = Screen()
win.makeKeyAndOrderFront(win)

我是新手,花了半天的时间搜索没有运气的事情。

0 个答案:

没有答案