2016-02-23 42 views
1

由於我是OS X開發人員的新手,對OS X組件的掌握不深。在我的應用程序中,我需要使用視圖覆蓋整個屏幕,但只有在隱藏菜單欄時才能執行此操作。與其他應用程序一樣,我想用菜單欄覆蓋整個屏幕。現在,我將視圖作爲彈出窗口呈現,但我的要求不是彈出視圖,而是覆蓋IOS中所有視圖的模糊視圖。 我的項目是在雨燕2.1帶菜單欄的封面屏幕OS X

我做了什麼

let presOptions: NSApplicationPresentationOptions = 
        ([ 
        .HideDock, 
        .HideMenuBar , 
        .DisableAppleMenu, 
        .DisableForceQuit, 
        .DisableProcessSwitching, 
        .DisableSessionTermination, 
        .DisableHideApplication, 
        .AutoHideToolbar 
        ]) 
      let optionsDictionary = [NSFullScreenModeApplicationPresentationOptions : 
       NSNumber(unsignedLong: presOptions.rawValue)] 

      self.view.enterFullScreenMode(NSScreen.mainScreen()!, withOptions:optionsDictionary) 
      self.view.wantsLayer = true 
} 

我的要求

enter image description here

我的輸出

enter image description here

回答

1

您應該創建NSWindow與水平NSScreenSaverWindowLevel - 1,根據這個鏈接它的工作原理:http://www.cocoabuilder.com/archive/cocoa/33048-floating-window-over-menu-bar.html

+0

我在這一行有錯誤,[ theWindowNR setLevel:NSScreenSaverWindowLevel - 1]; – ak2g

+1

當然,因爲它是Objective-C代碼,而不是Swift。 –

+0

我找不到setLevel,它在swift中是什麼? theWindowNR.setLevel = NSScreenSaverWindowLevel - 1 – ak2g

2

解決我的雨燕2.0

let newWindow = NSWindow(contentRect: NSMakeRect(0, 0, NSScreen.mainScreen()!.frame.width, NSScreen.mainScreen()!.frame.height), styleMask: NSBorderlessWindowMask, backing: NSBackingStoreType.Buffered, `defer`: false) 

func applicationDidFinishLaunching(aNotification: NSNotification) { 

    newWindow.title = "New Window" 
    newWindow.opaque = false 
    newWindow.backgroundColor = NSColor(calibratedHue: 0, saturation: 1.0, brightness: 0, alpha: 0.5) 
    newWindow.makeKeyAndOrderFront(nil) 
    newWindow.level = Int(CGWindowLevelForKey(CGWindowLevelKey.ScreenSaverWindowLevelKey)) 

}