Reputation: 788
How to receive a notification/callback when a NSView is moved - alternatively when a NSViewController is moved.
I see that there are methods for NSWindow (NSWindowDidMoveNotification) but I cannot find out how handle it with an NSView or NSViewController.
I understand that NSView has a NSWindow and that this is what has 'a coordinate' but I'm not sure how to subclass this NSWindow to overwrite the move method.
Upvotes: 1
Views: 671
Reputation: 788
I found out. Add an observer like this:
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(frameDidChange:)
name:NSViewFrameDidChangeNotification
object:self.view];
And a selector like this:
- (void)frameDidChange:(NSNotification*)notification {
NSView* view = [notification object];
...
}
Upvotes: 2