如果我有 asuperview.frame = CGRectMake(0,0,200,200);
和 a subview.frame = CGRectMake(0,0,100,100)
,子视图具有灵活的宽度和高度,我认为当 superview 的框架更改为 时(0,0,150,150)
,子视图的框架应该更改为(0, 0, 75, 75)
. 但事实并非如此。
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
UIView * view1 = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 200, 200)];
view1.backgroundColor = [UIColor blackColor];
[self.view addSubview:view1];
UIView * view2 = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)];
view2.backgroundColor = [UIColor redColor];
view2.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleTopMargin;
[view1 addSubview:view2];
view1.frame = CGRectMake(0, 0, 150, 150);
[self printRect:view2.frame];
}
- (void) printRect:(CGRect)rect
{
NSLog(@"%0.1f, %0.1f, %0.1f, %0.1f", rect.origin.x, rect.origin.y, rect.size.width, rect.size.height);
}
输出:
0.0, 0.0, 50.0, 50.0
而当superview的frame变为(0,0,100,100)时,subview的frame会变为(0,0,0,0)
为什么..