什么Swift代码会将应用切换到全屏? 我找到了IOS示例代码的参考资料。 我正在寻找适用于MacOS应用程序的代码。
答案 0 :(得分:3)
针对Swift 4进行了更新
override func viewDidAppear() {
let presOptions: NSApplication.PresentationOptions = [.fullScreen, .autoHideMenuBar]
let optionsDictionary = [NSView.FullScreenModeOptionKey.fullScreenModeApplicationPresentationOptions: presOptions]
view.enterFullScreenMode(NSScreen.main!, withOptions: optionsDictionary)
view.wantsLayer = true
}
答案 1 :(得分:3)
另一种选择,如果你想要不同的行为,当你将鼠标移动到顶部时,菜单栏是可用的。但是,它从正常大小的窗口开始然后增长,因此根据您正在做的事情可能不合适。
Plugin with id 'jp.classmethod.aws.lambda' not found.
答案 2 :(得分:2)
一种方法是覆盖viewDidAppear
中的NSViewController
:
class ViewController : NSViewController {
override func viewDidAppear() {
let presOptions: NSApplicationPresentationOptions = ([.FullScreen,.AutoHideMenuBar])
let optionsDictionary = [NSFullScreenModeApplicationPresentationOptions :
NSNumber(unsignedLong: presOptions.rawValue)]
self.view.enterFullScreenMode(NSScreen.mainScreen()!, withOptions:optionsDictionary)
self.view.wantsLayer = true
}
}