2011-06-25 1 views
0

私は3つのビューがあります。 1.メインビューで、他の2つのビューが含まれています。 2.最初のビューよりも大きなビューです。 3. 2番目のビューに含まれています。ContentMode scaleAspectToFitが機能しません

アスペクト比を維持している最初のビューのサイズに2番目のサイズ(と3番目のサイズ)をリサイズします。私はscaleToAspectFittにcontentModeを設定してこの結果を得ようとしますが、うまくいきません。私はこのような1つのビューの変更ここで

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]; 

答えて

0

- すべてのあなたのビューを変更する必要が

UIView *blueView = [[UIView alloc] initWithFrame:CGRectMake(0,0,350,400)]; 

    [blueView setAutoresizingMask:UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight]; 


    [blueView setContentMode:UIViewContentModeScaleAspectFit]; 
関連する問題