How to auto hide menu bar of the finder with Swift and MacOS?
I can see the Apple documentation https://developer.apple.com/documentation/appkit/nsapplication/presentationoptions/1428541-autohidemenubar
But I do not understand how to apply that. I would appreciate any orientation.
(By the way I know how to hide and show but what I am looling for is auto hide and only show when the user approach the cursor)
- If I have a button to autoHideMenuBar and another button to autoHideDock it seems they are not compatible. I looked at documentation and they say "If you specify autoHideMenuBar, it must be accompanied by either hideDock or autoHideDock" I should put both in the same button? If so, I do not know how to do that.
options are defined as a set.
@IBAction func showHide(_ sender: NSButton) {
let application = NSApplication.shared
let autoHidden = application.presentationOptions.contains(.autoHideMenuBar)
if autoHidden {
application.presentationOptions = []
} else {
application.presentationOptions = [.autoHideDock, .autoHideMenuBar]
}
}
- After I autoHideMenuBar, If I click outside the app the bar appears again. I would like to auto hide the menu bar and the dock always, not only when the user is in the app. (I would also like to let the user show both if he clicks another button)
That's normal. You control autoHide for your app only, it is not your app decision to hide manuBar for others !
To unhide, simply call:
NSApplication.shared.presentationOptions = []