我创建了一个信号来观察-viewDidLoad
中文本字段框架的宽度:
RACSignal *destinationDisplayWidthSignal =
[RACObserve(self.destinationNumberTextField, frame)
map:^id(NSValue *value) {
NSLog(@"rect: %@", NSStringFromCGRect([value CGRectValue]));
return @(CGRectGetWidth([value CGRectValue]));
}];
然而,在-viewDidAppear:
中的帧更改后,信号未发送下一个事件。我尝试将frame
替换为bounds
并且它有效!
我是否应该始终使用bounds
来观察U RACObserve()
?
答案 0 :(得分:8)
没有人回答,有些代码会调用-setFrame:
,而其他代码会调用-setBounds:
。如果设置rect的代码不是您的代码,那么您可以同时观察bounds
和frame
并合并这两个信号。例如:
[[[RACSignal
merge:@[RACObserve(view, frame), RACObserve(view, bounds)]]
logNext]
map:^(NSValue *value) {
return @(CGRectGetWidth([value CGRectValue]));
}]