How to detect an NSWindow Maximize or Zoom event?

How do you detect when a user clicks the green increase or increase (+) button in NSWindow without using NSWindowDidResizeNotification?

The reason I don’t want to use NSWindowDidResizeNotificationis because it also starts again when the user clicks and drags to manually resize the window. I have a code that I want to execute, and it should work only once when the user enlarges or cancels the window using the green button in the upper left corner and not many times when manually resizing the window.

+5
source share
2 answers

These two window delegate methods can be useful:

- windowWillUseStandardFrame:defaultFrame:
- windowShouldZoom:toFrame:

You can also consider subclassing NSWindow and overriding the method zoom:.

+9
source

@EagleOfToledo, based on your question and your comments on Todd Yandell's answer, I think you only need this delegation method:

Swift

optional func windowDidEndLiveResize(_ notification: NSNotification)

Objective-c

- (void)windowDidEndLiveResize:(NSNotification *)notification

This method will be called only after pressing the zoom button or manually resizing.

0
source

All Articles