Last Updated: February 25, 2016
·
4.554K
· rizo

Observing NSView Bounds

One solution to observer bounds changes in the NSView is to setup a notification in the default notification center and register a selector to respond to the changes.

// Somewhere in your view initialization method.
[self setPostsBoundsChangedNotifications:YES];

NSNotificationCenter *center = [NSNotificationCenter defaultCenter] ;
[center addObserver:self
           selector:@selector(boundsDidChangeNotification:)
               name:NSViewBoundsDidChangeNotification
             object:[scrollView contentView]];

Than add the selector that will be triggered when the notification is received:

- (void)boundsDidChangeNotification:(NSNotification *)notification
{
    // ...
}

And this is it. Now the selector boundsDidChangeNotification can be used to perform any action after the view's bounds change.