Reputation: 8637
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?
Upvotes: 0
Views: 4728
Reputation: 7483
Alternatively, you could use a custom superview that implements - (void)layoutSubviews
to have complete control over the layout.
Upvotes: 0
Reputation: 523694
You could implement the -sizeThatFits:
method for your view to keep the size in proportion.
Upvotes: 1
Reputation: 5382
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.
Upvotes: 1