Search code examples
iosobjective-ciphoneuiinterfaceorientation

iOS UIInterfaceOrientation


My iOS app supports both landscape and portrait. The splash screen, login view and the home view are all portrait.

Now if I rotate the device to landscape and start the app all three views are and stay in portrait which is what is needed. But if I start the app in portrait and during splash screen I rotate the device to landscape the login screen is shown in landscape then automatically moves to portrait. Same for home screen (auto login, when user has already logged in and reopened the app, it goes directly to home screen).

I used this

[[UIDevice currentDevice] setValue:[NSNumber numberWithInt:UIInterfaceOrientationPortrait] forKey:@"orientation"];

in viewDidLoad, viewDidAppear, viewWillAppear and viewWillDisappear. I also used

-(NSUInteger)supportedInterfaceOrientations{
return UIInterfaceOrientationMaskPortrait;
}

So, what I want to achieve is to keep the views in portrait even if I rotate the device during the splash screen.

Thank you.


Solution

  • There was a problem with the flow of the app that was causing the problem. The solutions provided by Ryan and Soberman are helpful. These lines of code should work fine supportedInterfaceOrientations NSNumber *value = [NSNumber numberWithInt:UIInterfaceOrientationPortrait]; [[UIDevice currentDevice] setValue:value forKey:@"orientation"];