macOS: fade out and close a window

macOS, Swift, Storyboards


I have two windows. I have opened the second window with a Storyboard Segue Kind Sheet. I want to close that window with a fade out. I put that in SecondViewController.swift. This works well to make the fade out. But, if I understand, the window is not visible but it is still there and I cannot click any button behind. How to solve that?


(If I use dismiss(self) I close the window but without the fade out. I want fade out, and then close)


@IBAction func close1(_ sender: NSButton) {


self.view.window?.animationBehavior = .none

self.view.window?.makeKeyAndOrderFront(nil)

NSAnimationContext.runAnimationGroup({ (context) -> Void in

context.duration = 2

self.view.window?.animator().alphaValue = 0

}, completionHandler: nil)


// dismiss(self)


}

Accepted Reply

I would create a completion handler (I did not test):


completionHandler: {
            self.view.window.orderOut(nil)       // Make sure to make it disappear
            self.view.window.alphaValue = 1  // For next show of window
}


Does it work ?

Replies

I would create a completion handler (I did not test):


completionHandler: {
            self.view.window.orderOut(nil)       // Make sure to make it disappear
            self.view.window.alphaValue = 1  // For next show of window
}


Does it work ?

Thank you!