我试图隐藏屏幕顶部的底座和菜单/聚光灯栏,基本上进入我的Cocoa OS X应用程序的kiosk模式。但是,我不想激活全屏模式。我希望应用程序正常运行,但只需隐藏桌面上的停靠栏和菜单/聚光灯区域,以阻止用户使用它们。我尝试过各种各样的选择,但似乎无法让它发挥作用。
https://developer.apple.com/library/mac/technotes/KioskMode/Introduction/Introduction.html
看起来这段代码的大多数实现都需要进入全屏或在Objective C中。有没有办法在Swift中执行此操作而不进入全屏模式?
更新 - 我想出了怎么做!我可以使用NSMenu隐藏菜单,但我必须通过访问终端隐藏Dock。可能有一种更简单,更清洁的方式,但我无法找到它。我希望这能帮助其他寻求解决方案的人!
import Cocoa
@NSApplicationMain
class AppDelegate: NSObject, NSApplicationDelegate {
var datastring = NSString()
func applicationDidFinishLaunching(aNotification: NSNotification) {
let task = NSTask()
let pipe = NSPipe()
task.standardOutput = pipe
task.launchPath = "/bin/bash/"
task.arguments = ["defaults write com.apple.dock tilesize -int 1", "killall -Kill Dock"]
let file:NSFileHandle = pipe.fileHandleForReading
task.launch()
task.waitUntilExit()
let data = file.readDataToEndOfFile()
datastring = NSString(data: data, encoding: NSUTF8StringEncoding)!
// Insert code here to initialize your application
}
func applicationWillTerminate(aNotification: NSNotification) {
// Insert code here to tear down your application
}
override func awakeFromNib() {
NSMenu.setMenuBarVisible(false)
}
}
}
答案 0 :(得分:0)
我想出了怎么做!我可以使用NSMenu隐藏菜单,但我必须通过访问终端隐藏Dock。可能有一种更简单,更清洁的方式,但我无法找到它。我希望这有助于其他寻求解决方案的人。
import Cocoa
@NSApplicationMain
class AppDelegate: NSObject, NSApplicationDelegate {
var datastring = NSString()
func applicationDidFinishLaunching(aNotification: NSNotification) {
let task = NSTask()
let pipe = NSPipe()
task.standardOutput = pipe
task.launchPath = "/bin/bash/"
task.arguments = ["defaults write com.apple.dock tilesize -int 1",
"killall -Kill Dock"]
let file:NSFileHandle = pipe.fileHandleForReading
task.launch()
task.waitUntilExit()
let data = file.readDataToEndOfFile()
datastring = NSString(data: data, encoding: NSUTF8StringEncoding)!
}
func applicationWillTerminate(aNotification: NSNotification) {
}
override func awakeFromNib() {
NSMenu.setMenuBarVisible(false)
}
}
}
答案 1 :(得分:0)
以下是您要找的内容吗?
斯威夫特3:
func applicationWillFinishLaunching(_ notification: Notification) {
NSApp.presentationOptions = [.autoHideDock, .autoHideMenuBar]
}
斯威夫特2:
func applicationWillFinishLaunching(notification: NSNotification) {
NSApp.presentationOptions = [.AutoHideDock, .AutoHideMenuBar]
}
(评论代码中的所有其他内容,或至少包含此处包含的代码)。