I am merging some code+xib layouts from an old iOS app into a current app.
All is working apart from layouts on iPhone 5/6. The original app does expand to fit those screens. However, I'm only using a subset of the view controllers from the old app, launched from a new button in the current app.
What I've been seeing is the iPhone 4 size layout occupying the top left of the screen on e.g. iPhone 6, when the view controller from the old code is loaded.
I've tried many different things. The one thing that made a slight difference was looking at the code for the old app's SplashScreen:
// Implement loadView to create a view hierarchy programmatically, without using a nib.
- (void)loadView {
//Init the View
CGRect appFrame = [[UIScreen mainScreen] applicationFrame];
UIView *view = [[UIView alloc] initWithFrame:appFrame];
view.autoresizingMask = UIViewAutoresizingFlexibleHeight |UIViewAutoresizingFlexibleWidth;
self.view = view;
[view release];
NSString *splashImageName = nil;
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
splashImageName = @"iPadDefault2.png";
else
splashImageName = @"Default.png";
mSplashImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:splashImageName]];
[self.view addSubview:mSplashImageView];
}
So I added the following to the HomeScreenViewController
which is the view launched from the new app:
- (void)loadView
{
[[[NSBundle mainBundle] loadNibNamed:@"HomeScreenViewController" owner:self options:nil] objectAtIndex:0];
self.view.autoresizesSubviews = YES;
[self.view setTranslatesAutoresizingMaskIntoConstraints:NO];
self.view.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
UIImage* backgroundImage = [UIImage imageNamed:@"Default-no-logo.png"];
self.view.backgroundColor = [UIColor colorWithPatternImage:backgroundImage];
CGRect appFrame = [[UIScreen mainScreen] applicationFrame];
[self.view setFrame:appFrame];
}
Now I get the background image tiled to fill the space on the iPhone 6, however the interface is still in the same place and size in the top left.
I've looked at answers such as UIView added programmatically full screen wrong size, creating a custom UIView, but it does not seem to help my situation.
EDIT:
If I change the loadView
method to:
NSString *splashImageName = nil;
splashImageName = @"Default-no-logo.png";
mSplashImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:splashImageName]];
mSplashImageView.contentMode = UIViewContentModeScaleAspectFit;
[mSplashImageView setFrame:appFrame];
[self.view addSubview:mSplashImageView];
I get the image show full screen. However, doing this with a custom UIView does not work. How can I get the UIView to respect the autoresizingMask
and grow with a larger display?
I've set debug points at various places and, for iPhone 6, it always says the height is 667.