I have a view controller with a view that changes (for example), and I would like to observe the frame of any view that self.view is set to. Is there any difference between:
[self.view addObserver:self forKeyPath:@"frame" options:0 context:nil];
and
[self addObserver:self forKeyPath:@"view.frame" options:0 context:nil];
For the second one, if the view changes will messages still be recieved when the new view's frame changes, or will it only send messages if the frame of the view that was set when the observer was added?
Is there any way to observe changes to the frame property even if the view of the view controller changes after adding the observer?
Use the second path. @"view.frame"
will notify you about the frame changes even when the "view" itself is changed. Cocoa will add observers for every object in the keyPath "chain" for you automatically (which means every item in the keyPath must be KVO-compatible).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With