2016-07-28 8 views
1

のサイズを変更する際、私は正しくリサイズサブビューを処理することはできませんよ。自動サイズ変更サブビュースーパー

それはUIImageViewが含まれている内部の私は、カスタムUIViewクラスを持っていると仮定します。

は当初、私は以下のようなUIViewsを設定します。

// width and height are UIImage width height 
// it is possible that the UIImage width height is larger than the container 

self.imageView.frame = CGRectMake(0 ,0, width, height) 
self.imageView.backgroundColor = UIColor.redColor() 
self.imageView.contentMode = UIViewContentMode.ScaleAspectFit 
self.imageView.autoresizingMask = [.FlexibleWidth, .FlexibleHeight,.FlexibleTopMargin, .FlexibleLeftMargin, .FlexibleRightMargin, .FlexibleBottomMargin] 
addSubview(self.imageView) 

self.frame = CGRectMake(0, 0, width, height) 
self.backgroundColor = UIColor.greenColor() 

はのはMYVIEWとしてこのカスタムUIViewのを呼ぶことにしましょう。

そして、この "myView"をViewControllerに配置したいとき。私は次のことをしました:

myView.frame = CGRectMake(xPos, yPos, 100, 100) 
myView.autoResizeSubviews = true 

そして私はこれを行った後、次の結果を得ました。 MyView place at the correct place with correct size, but the internal UIImageView got even a smaller size.

なぜですか。 MyView内のすべてのサブビューをMyViewのフレームに従って正しくサイズ変更するにはどうすればよいですか?

ありがとうございました。

答えて

0

あなたは、自動レイアウトを使用していない場合

あなたが自己の後枠を設定していることを確認(UIViewの)割り当て

self.frame = CGRectMake(0, 0, width, height) 
self.imageView.autoresizingMask = [.FlexibleWidth, .FlexibleHeight,.FlexibleTopMargin, .FlexibleLeftMargin, .FlexibleRightMargin, .FlexibleBottomMargin] 
addSubview(self.imageView) 
2

してくださいああ、私は自動サイズ変更マスクがあるべきことがわかっ怒鳴るの行を入れ替えます次のように設定します。

これにより、アンカーを上下に固定でき、他の余白にもサイズを変更できます。

関連する問題