I want to show an image to the user when they launch the App. This image is being shown for 20 seconds.
I'd like to have a functionality where ,when a user launches the App in Landscape, the App stays in Landscape. And when a user lauches the App in Portrait, the App stays in Portrait.
I was realy having a hard time configuring this in the Appdelegate so I made a seperate viewcontroller for showing this image. When the timer is finished I navigate to the next view where rotation should be enabled.
So how can I temporary lock the UI of the iPad?
Edit:
I fixed this by implementing a orientation check within viewDidLoad in the first Viewcontroller after my Appdelegate. For every orientation I saved a value. When performing shouldAutorotate: I first check for the saved value which disables orientation changes.
Solution in code:
- (void)viewDidLoad {
[super viewDidLoad];
NSUserDefaults * defaults = [NSUserDefaults standardUserDefaults];
if (UIDeviceOrientationIsLandscape([UIDevice currentDevice].orientation)) {
[[NSUserDefaults standardUserDefaults] setInteger:1 forKey:@"PortraitLandscapeIndicator"];
}
else {
[[NSUserDefaults standardUserDefaults] setInteger:0 forKey:@"PortraitLandscapeIndicator"];
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
//the latest saved orientation is our orientation
if([[NSUserDefaults standardUserDefaults] integerForKey:@"PortraitLandscapeIndicator"] == 1){
return ((interfaceOrientation == UIInterfaceOrientationLandscapeLeft) || (interfaceOrientation == UIInterfaceOrientationLandscapeRight));
}
else{
return ((interfaceOrientation == UIInterfaceOrientationPortrait) || (interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown));
}
}
Sounds like you will have to do something where a special viewController gets shown on start that in the loadView or init gets device orientation, then sets the views frame appropriately and which based on whatever mode portrait or landscape it is then only returns the allowed orientation from the [shouldAutorotateToInterfaceOrientation:].
After your timer is up, you can pass control to some other viewController to take it from there or subsequently allow other orientations.
But bottom line this is something I think you are going to have to do programmatically via whatever scheme works best for you.