ContentMode scaleAspectToFit不起作用

| 我有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];
    
已邀请:
        在这里,我更改了这样的一种视图-您必须修改所有视图
    UIView *blueView = [[UIView alloc] initWithFrame:CGRectMake(0,0,350,400)];

    [blueView setAutoresizingMask:UIViewAutoresizingFlexibleWidth |  UIViewAutoresizingFlexibleHeight];


    [blueView setContentMode:UIViewContentModeScaleAspectFit];
    

要回复问题请先登录注册