I've got an iPhone app with a UIViewController
as the first controller. In it, I've got the standard methods that force it to be landscape (see below).
I've also got a second view that I show as a modal in the viewWillAppear -- it's meant as a splash screen while I pull down some content from the 'net.
The problem happens when I physically rotate my device into landscape mode and start the app. The modal shows (in portrait), but when it gets dismissed a few seconds later, the main view is displayed in landscape.
On the other hand, if I comment out the code for the modal and launch the app in landscape, the main view shows up in portrait as it should.
Any suggestions on how I can keep the main view in portrait mode when the app is launched from landscape?
- (void)viewWillAppear:(BOOL)animated {
// Show the loading splash screen until the webview has completed
[self performSegueWithIdentifier:@"sgImageModal" sender:self];
}
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([segue.identifier isEqualToString:@"sgImageModal"]) {
splashScreen.modalPresentationStyle = UIModalPresentationFullScreen;
}
}
- (BOOL)shouldAutorotate {
return NO;
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated {
[self viewWillAppear:animated];
}
- (NSUInteger)supportedInterfaceOrientations{
return UIInterfaceOrientationMaskPortrait;
}
-(UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
return UIInterfaceOrientationPortrait;
}
Update 1
As per suggestions, I've moved the logic to display the modal into viewDidAppear and viewDidLoad. I also changed shouldAutorotate to return YES. Neither had the desired impact.