I am able to show and hide my NSWindows titlebar in one of two ways via an action method containing :
window.titlebarAppearsTransparent = true
window.movableByWindowBackground = true
or preferably :
window.styleMask = NSBorderlessWindowMask
window.movableByWindowBackground = true
window.canBecomeKeyWindow
Am I able to animate this with a fade effect in any way..? Or would that involve a far more convoluted method of showing and hiding the windows titlebar..?
Ok I have found a solution to showing and hiding the NSWindow titlebar with an animated effect.
You could implement this in any method, I have the titlebar fading out on a text changed event method, and fading back in with any movement.
Fade out the titlebar :
if window.standardWindowButton(NSWindowButton.ZoomButton)?.superview?.alphaValue > 0.1 {
window.standardWindowButton(NSWindowButton.ZoomButton)?.superview?.animator().alphaValue = 0
}
Fade in the titlebar :
if window.standardWindowButton(NSWindowButton.ZoomButton)?.superview?.alphaValue < 1 {
window.standardWindowButton(NSWindowButton.ZoomButton)?.superview?.animator().alphaValue = 1
}
So we are getting the titlebar view by the fact that it is the superview of the standardWindowButtons. And simply animating the alpha value of the titlebar view.
Gary Simpson's answer refactored.
extension NSWindow {
func setTitleBarHidden(hidden: Bool, animated: Bool = true) {
let buttonSuperView = standardWindowButtonSuperView()
if buttonSuperView == nil {
return
}
let view = buttonSuperView!
if hidden {
if view.alphaValue > 0.1 {
if !animated {
view.alphaValue = 0
return
}
view.animator().alphaValue = 0
}
return
}
if view.alphaValue < 1 {
if !animated {
view.alphaValue = 1
return
}
view.animator().alphaValue = 1
}
}
func standardWindowButtonSuperView() -> NSView? {
//http://stackoverflow.com/a/28381918
return standardWindowButton(NSWindowButton.ZoomButton)?.superview
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With