Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NSWindow event when change size of window

Tags:

objective-c

what is method call when change size in Window? I find somesing aboud windowDidResize: so i try doing

- (void)windowDidResize:(NSNotification *)notification {
    NSLog(@"test");
}

I found what need use NSWindowDidResizeNotification, but I work for the first time with NSNotification and bad understand about this. Can somebody write a full example for my event, please?

like image 821
Pavel Avatar asked Dec 17 '22 01:12

Pavel


1 Answers

The -windowDidResize: method is called on the window delegate. Is the object with the method you posted the delegate for the window?

For something other than the delegate, you can do:

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(windowDidResize:) name:NSWindowDidResizeNotification object:theWindow];

and, when the observer is no longer interested or being deallocated:

[[NSNotificationCenter defaultCenter] removeObserver:self name:NSWindowDidResizeNotification object:theWindow];

Another approach is to use the new block-based API to NSNotificationCenter:

id observation = [[NSNotificationCenter defaultCenter] addObserverForName:NSWindowDidResizeNotification object:theWindow queue:nil usingBlock:^(NSNotification *){
    NSLog(@"test");
}];
// store/retain the observation for as long as you're interested in it. When it's deallocated, you stop observing.
like image 194
Ken Thomases Avatar answered Jan 06 '23 14:01

Ken Thomases