I have a UIView that contains a UIImageView. UIImageViews works as an app brand logo. When I rotate the device containing the UIView, it resizes to fit the landscape or portrait proportions of the screen.
I am trying to get the UIImageView to scale accordingly, keeping the proportions also in the left margin.
This is the actual code for the top white banner:
UIView *topBanner = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, height_topBanner)]; [topBanner setAutoresizingMask:(UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight|UIViewAutoresizingFlexibleTopMargin|UIViewAutoresizingFlexibleBottomMargin)]; [topBanner setBackgroundColor:[UIColor whiteColor]]; topBanner.autoresizesSubviews = YES;
This is my starting point: iPad portrait at startup:

This is what happens when I rotate it in the landscape: 
As you can see, the proportions of the UIImage are fine, but I get extra borders (I set the background color of the UIImageView to highlight it), because the UIImageView is stretched to keep track of the resizing of its container, and the UIImage fits into the UIImageView and fits in its center .
The same thing - the opposite - happens when I launch the application directly in landscape mode: 
Then rotate it:

... and I get a logo with extra borders at the top and bottom.
I see that I can write a function to recalculate each size each time the rotation changes, but I ask myself if there is a way to set UIImageView and UIImage so that it works without breaking the autorotation / resizing of the iOS procedure. It sounds so simple!
source share