I have a NSWindowController with an NSWindow,
I am having an issue where, if I set the controller's contentViewController, the frame of the NSWindow updates beyond my expectations
- Window is at a origin, say (500,500), and size is (100,100)
- I drag it to (300,300)
- I press a control which updates
contentViewController - The size remains at (100,100), but the origin goes back to (500, 500)
The entire window remains the same size, but it just moves back to the original position
This is the code that updates the frame
self.contentViewController = loadingViewController
I confirmed this by printing out the window's frame in lldb, before and after this line:
▿ Optional<CGRect>
▿ some : (-1701.0, 439.0, 1042.0, 778.0)
▿ origin : (-1701.0, 439.0)
- x : -1701.0
- y : 439.0
▿ size : (1042.0, 778.0)
- width : 1042.0
- height : 778.0
(lldb) po self.window?.frame
▿ Optional<CGRect>
▿ some : (-1680.0, 416.0, 800.0, 778.0)
▿ origin : (-1680.0, 416.0)
- x : -1680.0
- y : 416.0
▿ size : (1042.0, 778.0)
- width : 1042.0
- height : 778.0
What is even more mysterious, is that I originally tried 3 separate places to catch the window moving to locate the line of code causing it
I registered as an observer:
NotificationCenter.default.addObserver(self, selector: #selector(windowMoved(notification:)), name: NSWindow.didMoveNotification, object: nil)
as well as setting symbolic breakpoints on:
-[NSWindow _windowMoved:] and -[NSWindow _setFrame:]
All 3 of these methods caught window movement when I manually dragged the window around.
However, none of the 3 caught the window moving when the frame was changed programmatically from that one line of code above ^^
Has anybody seen this before, or have an idea of how this could be?