问题:
在全屏Mac应用程序上,当您将鼠标指针移动到顶部时,mac菜单栏将立即下拉。我想创建一个应用程序,将菜单栏的显示延迟几秒钟。
应该可以,因为这是VMWare Fusion的确切行为。在全屏模式下,应用程序让鼠标指针位于屏幕顶部几秒钟,然后再下拉菜单栏。
我将如何解决这个问题?
----更新----
当我想使用NSMenu.setMenuBarVisible()时,我可以隐藏和显示菜单栏。
但是,如果我在全屏幕上有多个窗口应用程序,这似乎不会起作用。
它适用于其中一个全屏窗口,但如果我切换到另一个全屏窗口,我必须在调用setMenuBarVisible(true)之前移动鼠标才会生效。
代码
public class CustomWindowController: NSWindowController, NSWindowDelegate {
override public func windowDidLoad() {
window!.delegate = self
}
public class func create() -> CustomWindowController {
let storyboard = NSStoryboard(name: "Main", bundle: nil)
let controller = storyboard.instantiateControllerWithIdentifier("CustomWindowController") as! CustomWindowController
controller.window?.collectionBehavior.insert(.FullScreenDisallowsTiling)
return controller
}
// MARK: NSWindowDelegate protocol
public func windowDidEnterFullScreen(notification: NSNotification) {
print("window did enter fullscreen")
NSMenu.setMenuBarVisible(false)
}
public func windowDidBecomeKey(notification: NSNotification) {
print("window did become key")
NSMenu.setMenuBarVisible(false)
}
}
public class CustomWindow: NSWindow {
// right now I'm using mouse click to trigger the showing of the menu bar
// but my end goal is to use timer to trigger the showing of the menu bar
// to delay the menu bar showing by a couple seconds
public override func mouseUp(theEvent: NSEvent) {
NSMenu.setMenuBarVisible(true)
}
}
class CustomViewController: NSViewController {
private var otherWindowControllers = [CustomWindowController]()
// button to spawn a second identical window
@IBAction func spawnWindowButton(sender: AnyObject) {
let controller = CustomWindowController.create()
controller.showWindow(self)
// needed at least 1 strong reference to prevent the window to go away,
// so we save the controller to a list
otherWindowControllers.append(controller)
}
deinit {
otherWindowControllers.removeAll()
}
}
Repro:
知道为什么会这样吗?以及如何修复它以使全屏窗口都具有正确的行为