QQ726535609 QQ726535609 - 5 months ago 47
iOS Question

iOS:Used type 'CGRect' (aka 'struct CGRect') where arithmetic or pointer type is required

When I use

ReactiveCocoa
,I want to observe my
tableView
's frame, but there comes a issue:

__block CGRect tmp_rect;
[RACObserve(self, self.tableView.frame) subscribeNext:^(id x) {
NSLog(@"%@",x);

tmp_rect= (CGRect)x; // this line appear issue:
'Used type 'CGRect' (aka 'struct CGRect') where arithmetic or pointer type is required'

double width_radio = x.origin.x/[UIScreen mainScreen].bounds.size.width;

back_nav.alpha = 1 - width_radio;
}];


I don't know what this issue appear.

Answer

The object x is an NSValue.

You need to unwrap the CGRect from it. You can't just cast it.

Try...

tmp_rect = [x CGRectValue];