I have a UIView subclass which in turn has a contentView, declared as such in the public header:
@property (nonatomic,retain)UIVivew* contentView;
I’m trying to get KVO notifications whenever contentView’s frame changes but the observeValueForKeyPath method is not being ever called in my UIView subclass:
@implementation MyView
@synthesize contentView = _contentView;
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
// Initialization code
[self.contentView addObserver:self
forKeyPath:@"frame"
options:(NSKeyValueObservingOptionNew | NSKeyValueObservingOptionOld)
context:nil];
}
return self;
}
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context {
if ([keyPath isEqualToString:@"frame"]) {
CGRect newContentFrame = [[change objectForKey:NSKeyValueChangeNewKey] CGRectValue];
CGRect selfNewFrame = self.frame;
selfNewFrame.size = CGSizeMake(newContentFrame.size.width + 10, newContentFrame.size.height + 10);
self.frame = selfNewFrame;
}
[super observeValueForKeyPath:keyPath ofObject:object change:change context:context];
}
Any ideas as to why is KVO not firing?
Sorry… sleep deprivation I guess…
Forgot to alloc / init the contentView.