Automatically scaling UIView and all contents on rotation
This should be simple but it just eludes me now.
I have an app in portrait mode, and when tilting the device into landscape mode, I just want all of the content to aspect scale down so that all content is displayed in the center of the screen, which would cause empty space on the left and right sides (this is fine). How do I set this up in Interface Builder? I have one containing UIView 开发者_运维技巧and am hoping that by having that one properly resized, all of the UIImageViews etc should also be aspect scaled down.
So this is the answer from Rincewind over at Apple's forums... it worked out for me. I had to work on the contentMode and autoscaling parameters properly for all subviews of the top view, which I resized (changed its frame) when orientation changes.
You should set the contentMode of your UIView to UIViewContentModeScaleAspectFit. You can configure this in Interface Builder via the ContentMode popup. Keep in mind that by setting this your view will not redraw without you calling -setNeedsDisplay manually. Keep in mind that if your view starts small and grows that it will simply zoom your small content until you redraw the view.
精彩评论