我有3个视图。1.它是主视图,包含另外两个视图。2.它是一个比第一个更大的视图。3.它包含在第二个视图中。
我想将第二个视图(显然也是第三个视图)的大小调整为第一个视图的大小,保持纵横比不变。我尝试将contentMode设置为scaleToAspectFitt以获得此结果,但它不起作用。
UIView *yellowView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 200, 200)];
yellowView.autoresizesSubviews = YES;
yellowView.backgroundColor = [UIColor yellowColor];
yellowView.autoresizesSubviews = YES;
yellowView.contentMode = UIViewContentModeScaleAspectFit;
UIView *blueView = [[UIView alloc] initWithFrame:CGRectMake(0,0,350,400)];
blueView.autoresizesSubviews = YES;
blueView.contentMode = UIViewContentModeScaleAspectFit;
blueView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
UIView *darkView = [[UIView alloc] initWithFrame:CGRectMake(200, 100, 40, 40)];
darkView.backgroundColor = [UIColor blackColor];
darkView.contentMode = UIViewContentModeScaleAspectFit;
darkView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
[blueView addSubview:darkView];
[yellowView addSubview:blueView];
[self.view addSubview:yellowView];
[yellowView setNeedsLayout];
[darkView release];
[blueView release];
[yellowView release];发布于 2011-06-25 20:56:58
在这里,我更改了一个视图,如下所示--您必须修改所有视图
UIView *blueView = [[UIView alloc] initWithFrame:CGRectMake(0,0,350,400)];
[blueView setAutoresizingMask:UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight];
[blueView setContentMode:UIViewContentModeScaleAspectFit];https://stackoverflow.com/questions/6477017
复制相似问题