1

I'm recreating my UI with auto layout and have a navbar across the top and a 2x2 grid of UIImageViews filling the rest of the screen. I put in all the constraints so it maintains this arrangement in any orientation and it's working well when the UIImageViews don't have an image in them. When I programmatically load an image in the UIImageViews, they change size and placement even though I have constraints that should prevent this.

I have all the autoresizing masks off for everything and the UIImageViews set to Aspect fit.

This autolayout stuff is new to me, but I thought I had it working...until I put an image in there. Why would that change the size and placement of the UIImageViews?

Thanks for the help!

4

1 に答える 1

3

ビューコントローラのアウトレットとリンクすると、実行時に制約を変更できます。

あなたの場合、幅と高さの制約を追加し、それらを2つのコンセントにリンクします。次に、画像の寸法がわかったら、定数値を変更します。

私はここで私が持っていた同様のユースケースについてこれを詳細に説明しています:http://www.cocoanetics.com/2012/11/first-good-auto-layout-use-case/

于 2012-12-22T06:58:23.070 に答える