I have an app that is portrait mode only, but when the user plays a video I want it to play in fullscreen landscape mode (the video player doesn\'t look good in portrait mod
I had the same situation, but I am using iOS 6 and a NavController based project. What makes that interesting is the ViewController that is hosting the MPMoviePlayerController I don't want rotated, but I wanted the video within it to be rotated.
I just manually rotate the MPMoviePlayerController as needed based on the devices orientation. _videoView is a MPMoviePlayerController property of the ViewController. For the example, I just hard coded the desired width and height to a 16x9 aspect ratio as I intend this video to be uploaded to youtube.
- (void)updateVideoRotationForCurrentRotationWithAnimation:(bool)animation
{
CGSize containerSize = _videoView.frame.size; // Container NOT rotated!
float videoWidth = 384; // Keep 16x9 aspect ratio
float videoHeight = 216;
if( animation )
{
[UIView beginAnimations:@"swing" context:nil];
[UIView setAnimationDuration:0.25];
}
switch( self.interfaceOrientation )
{
case UIInterfaceOrientationPortrait:
case UIInterfaceOrientationPortraitUpsideDown:
m_videoPlayer.view.transform = CGAffineTransformMakeRotation(radians(90));
// This video player is rotated so flip width and height, but the container view
// isn't rotated!
[m_videoPlayer.view setFrame:CGRectMake((containerSize.width-videoHeight)/2,
(containerSize.height-videoWidth)/2,
videoHeight,
videoWidth)];
break;
case UIInterfaceOrientationLandscapeLeft:
case UIInterfaceOrientationLandscapeRight:
m_videoPlayer.view.transform = CGAffineTransformMakeRotation(radians(0));
// This video player isn't rotated
[m_videoPlayer.view setFrame:CGRectMake((containerSize.width-videoWidth)/2,
(containerSize.height-videoHeight)/2,
videoWidth,
videoHeight)];
break;
}
if( animation )
[UIView commitAnimations];
}
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
{
[self updateVideoRotationForCurrentRotationWithAnimation:YES];
}
I also call updateVideoRotationForCurrentRotationWithAnimation after view did appear so it has the correct initial orientation.