简体   繁体   中英

Determine when a NSWindow is closing versus leaving full screen

I have a NSWindow that goes into full screen. My NSWindowController is an observer of the NSWindowWillCloseNotification notification.

I would like to do something special when the window is closed (As in the user presses the red X button in the top left hand corner) but I also get the NSWindowWillCloseNotification notification when the user leaves full screen mode, in which case I do not want anything to happen.

Is there a way to determine inside of the selector I set up to be called when I observe the NSWindowWillCloseNotification notification? At the point my selector is called, the NSWindow has already left full screen, so I cannot check if it is full screen or not. Also the NSNotifications 's UserInfo dictionary is nil.

Thanks,

Will

Turns out I was getting the notification from a window that wasn't my NSWindowController 's window!

Printing out the notification that I was receiving we can see that I was getting the NSWindowWillCloseNotification call for a NSToolbarFullScreenWindow :

NSConcreteNotification 0x6080002578b0 {name = NSWindowWillCloseNotification; object = <NSToolbarFullScreenWindow: 0x100d57f50>}

I should have wrote my observer method like this, rather than passing nil for object:

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleWindowWillClose:) name:NSWindowWillCloseNotification object:self.window];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM