3

I have an NSWindow which is being shown using an NSWindowController. If I set the window level to anything but zero and then miniaturize and deminiaturize the window it disappears. The animation shows the window deminiaturizing but it disappears as soon as the animation ends.

class ViewController: NSViewController {

    var controller:NSWindowController?

    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.
    }

    override var representedObject: Any? {
        didSet {
        // Update the view, if already loaded.
        }
    }
    @IBAction func buttonPressed(_ sender: Any) {

        self.controller = NSWindowController(windowNibName: .init("FloatingWindowController"))
        self.controller?.window?.level = .floating
        self.controller?.showWindow(nil)
    }
}
BenJacob
  • 957
  • 10
  • 31
  • Correct but when I have the window controller kept around as a variable of the view controller, the same behaviour occurs. I have updated the question to reflect this. – BenJacob Oct 01 '18 at 11:34
  • I tried your code and the window doesn't disappear. – Willeke Oct 01 '18 at 15:16
  • Can I ask which version of OS X and Xcode you are using? I'm very confused as to why no-one else seems to be replicating this. – BenJacob Oct 01 '18 at 15:23
  • macOS 10.13.6 and Xcode 9.4.1. How did you create the XIB and which settings and/or outlets of the window and window controller did you change? – Willeke Oct 01 '18 at 22:46
  • I created the XIB by going through New File > Cocoa Class and creating an NSWindowController with associated XIB. I then added an NSButton and created an IBAction `buttonPressed` which you can see in the above code. – BenJacob Oct 02 '18 at 07:42
  • I think I might have found why I can reproduce the issue and you cannot. I have the dock setting "Minimise windows into application icon" enabled. When I disable this (as is the default) the issue goes away. – BenJacob Oct 02 '18 at 08:21
  • Yes, the window disappears. It looks like a bug to me. Note: from [Human Interface Guidelines](https://developer.apple.com/design/human-interface-guidelines/macos/windows-and-views/panels/): "In general, disable the Minimize button on a panel. A panel shouldn’t need to be minimized because it’s only displayed when needed and disappears when the app is inactive." – Willeke Oct 02 '18 at 13:15
  • Try a workaround: subclass `NSWindow`, override `miniaturize`, set `level` to `.normal`, call `super` and set `level` back to `.floating`. – Willeke Oct 02 '18 at 14:01

0 Answers0