I NEED: rotate device programmatically from portrait to landscape compatible for iOS6 and iOS5.
THE PROBLEM: I cannot use [UIDevice setOrientation]
function on ios6.
WHAT I HAVE: the code for iOS6:
- (BOOL) shouldAutorotate
{
return YES;
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
return UIInterfaceOrientationLandscapeLeft;
}
the code for iOS5:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return YES;
}
So, I need write the code that rotate on iOS5:
-(void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
// [[UIDevice currentDevice] setOrientation] - I cannot use it
// ???
}
I achieved this by set Status bar orientation, try execute in code:
[[sharedApplication] setStatusBarHidden:YES];
[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeRight];
and when you need portrait mode, set status bar to setStatusBarHidden:NO
and again set statusbar orientation to portrait UIInterfaceOrientationPortrait
.