In my app i support only portrait mode and use UINavigationController
as RootViewController
. But when i am playing movie using MPMoviePlayerController
and Player is Fullscreen than i want it to support both landscape
mode Also.
Does this using this great code by @ChrisBallinger this in iOS6 but its not working in iOS5
After long search on google i am not able to find the solution so posted here. Please help with this problem.
I have also tried to subclassing the navigationcontroller
and set the Rotate code it found here but no luck.
My sandbox app:
https://github.com/comonitos/programatical_device_orientation
The solution is easy:
in interface (h file) :
BOOL rotated;
in implementation (m file):
1. rewrite
-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return rotated;
}
2 call [self setup]
-(void) setup {
rotated = YES;
[[UIDevice currentDevice] setOrientation:UIDeviceOrientationLandscapeLeft];
rotated = NO;
}
what you will have to do is...
first implement notification in viewdidload method like below...
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(rotate:)
name:UIDeviceOrientationDidChangeNotification
object:nil];
Now implement that rotate method like below..
#pragma mark - Rotate Screen Method
- (void)rotate:(NSNotification *)n {
// if (!isFullScreen)
// return;
switch ([[UIDevice currentDevice] orientation]) {
case UIDeviceOrientationLandscapeLeft:
playerView.transform = CGAffineTransformMakeRotation(M_PI / 2);//playerview is view in which you have added MPMoviePlayerViewController object
playerView.frame = CGRectMake(0, 0, 768, 1024);
break;
case UIDeviceOrientationLandscapeRight:
playerView.transform = CGAffineTransformMakeRotation(-M_PI / 2);
playerView.frame = CGRectMake(0, 0,768, 1024);
break;
case UIDeviceOrientationPortrait:
playerView.transform = CGAffineTransformIdentity;
playerView.frame = CGRectMake(0, 0, 768, 1024);
break;
case UIDeviceOrientationPortraitUpsideDown:
playerView.transform = CGAffineTransformMakeRotation(M_PI);
playerView.frame = CGRectMake(0, 0, 768, 1024);
break;
default:
break;
}
}
let me know it is working or not!!!
Happy Coding!!!