我正在尝试使应用程序以演示模式启动,同时禁用 Dock、菜单栏、进程切换等。到目前为止,我有以下代码:
let presOptions: NSApplicationPresentationOptions =
.HideDock | // Dock is entirely unavailable. Spotlight menu is disabled.
// .AutoHideMenuBar | // Menu Bar appears when moused to.
// .DisableAppleMenu | // All Apple menu items are disabled.
.DisableProcessSwitching | // Cmd+Tab UI is disabled. All Exposé functionality is also disabled.
.DisableForceQuit | // Cmd+Opt+Esc panel is disabled.
.DisableSessionTermination | // PowerKey panel and Restart/Shut Down/Log Out are disabled.
.DisableHideApplication | // Application "Hide" menu item is disabled.
// .AutoHideToolbar |
.FullScreen
let optionsDictionary = [NSFullScreenModeApplicationPresentationOptions: presOptions]
browserWindowController.containerView.enterFullScreenMode(NSScreen.mainScreen()!, withOptions: optionsDictionary)
在 .HideDock 行上,我收到错误:
如果没有更多上下文,表达类型不明确
有人可以帮我找到解决方案并解释错误的含义吗?
还在 browserWindowController 行上收到错误:
使用未解析的标识符“browserWindowController”
有人可以向我解释为什么这不起作用吗?
对于 Swift 2
NSApplicationPresentationOptions
必须是一个数组:
let presOptions: NSApplicationPresentationOptions = [
.HideDock, // Dock is entirely unavailable. Spotlight menu is disabled.
// .AutoHideMenuBar, // Menu Bar appears when moused to.
// .DisableAppleMenu, // All Apple menu items are disabled.
.DisableProcessSwitching, // Cmd+Tab UI is disabled. All Exposé functionality is also disabled.
.DisableForceQuit, // Cmd+Opt+Esc panel is disabled.
.DisableSessionTermination, // PowerKey panel and Restart/Shut Down/Log Out are disabled.
.DisableHideApplication, // Application "Hide" menu item is disabled.
// .AutoHideToolbar,
.FullScreen
]
至于
browserWindowController
错误,它只是意味着Swift编译器不知道这个变量是什么。它可能已在其当前使用范围之外定义,甚至根本没有声明。
我已经更新了 swift 4.2 的代码。看看吧。
//Enter kiosk mode
func KisokMode(){
let presOptions: NSApplication.PresentationOptions = [
.hideDock, // Dock is entirely unavailable. Spotlight menu is disabled.
.autoHideMenuBar, // Menu Bar appears when moused to.
.disableAppleMenu, // All Apple menu items are disabled.
.disableProcessSwitching, // Cmd+Tab UI is disabled. All Exposé functionality is also disabled.
.disableForceQuit, // Cmd+Opt+Esc panel is disabled.
.disableSessionTermination, // PowerKey panel and Restart/Shut Down/Log Out are disabled.
.disableHideApplication, // Application "Hide" menu item is disabled.
.autoHideToolbar,
.fullScreen
]
let optionsDictionary = [NSView.FullScreenModeOptionKey.fullScreenModeApplicationPresentationOptions: presOptions]
TheWindowExample.contentView?.enterFullScreenMode(NSScreen.main!, withOptions: optionsDictionary)
}
TheWindowExample 是您要在其中使用 kiosk 模式的窗口。
如果有人在 SwiftUI 时代处理这个用例,我发现添加
<key>LSUIPresentationMode</key><real>3</real>
Info.plist 中将禁用全屏应用程序的菜单和停靠栏。
我在文档存档中找到了它,其中包含以下值描述。
全隐藏模式。在此模式下,所有 UI 元素都被隐藏,包括菜单栏。元素不会自动显示自己以响应鼠标移动或用户活动。
它似乎仍然是活动文档的一部分: