0
我有一個UIView子類,又具有內容查看,在公共頭宣佈爲:爲什麼KVO不能在UIView子類上工作?
@property (nonatomic,retain)UIVivew* contentView;
我試圖讓國際志願者組織的通知,只要內容查看的框架發生改變,但observeValueForKeyPath方法不被永遠叫在我的UIView子類:
@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];
}
任何想法爲什麼KVO不開火?
那麼這個問題解決了嗎?儘可能選擇它作爲答案 - 謝謝! – 2012-08-11 01:07:21
YE它做到了。但是,在2天之內,我不會讓我選擇我自己的答案...... – SaldaVonSchwartz 2012-08-11 04:16:40