I have a UIView whose height should always be exactly 1.5 times the width. When the view is auto-resized (in this case, because the iPhone is rotated), this proportion gets messed up. How can I make sure the height/width ratio doesn't change as the view resizes?
A:
You need to set the views autoresizingMask
property to UIViewAutoresizingNone
. This will prevent the size of the view from changing at all when the parent view's size changes (such as when the phone rotates.) If you want the view to resize on rotation, but maintain it's aspect ratio (for example if you want it wider in landscape but still 1:1.5), then you will need to set the view's frame yourself to the desired dimensions (but maintaining the desired ratio) in the view controller's willRotateToInterfaceOrientation:duration:
method.
Jason Jenkins
2010-06-30 18:25:59
A:
You could implement the -sizeThatFits:
method for your view to keep the size in proportion.
KennyTM
2010-06-30 20:45:06