Last Updated: February 25, 2016
· 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
             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.