I create a signal to observe the width of a text field's frame in -viewDidLoad
:
RACSignal *destinationDisplayWidthSignal =
[RACObserve(self.destinationNumberTextField, frame)
map:^id(NSValue *value) {
NSLog(@"rect: %@", NSStringFromCGRect([value CGRectValue]));
return @(CGRectGetWidth([value CGRectValue]));
}];
However, the signal did not send the next event after the frame changes in -viewDidAppear:
. I try to replace frame
with bounds
and it works!
Should I always observe the bounds
of a UIView using RACObserve()
?
There's no one answer, some code will call -setFrame:
, while other code will call -setBounds:
. If the code that sets the rect is not your code, then you could observe both bounds
and frame
and merge the two signals. For example:
[[[RACSignal
merge:@[RACObserve(view, frame), RACObserve(view, bounds)]]
logNext]
map:^(NSValue *value) {
return @(CGRectGetWidth([value CGRectValue]));
}]
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