I have a requirement where the interface, which contains a video, is portrait only but when the user rotates to landscape the video goes to full screen and starts playing then when the video reaches the end or the user clicks done, the video exits full screen and the interface is still portrait. I have tried to use shouldAutorotateToInterfaceOrientation: methods which works for starting the video. But I cannot get the screen to rotate back again. I have decided to instead use shouldAutorotateToInterfaceOrientation: and create my own view controller to handle the video only and use -[UIView setTransform:] to rotate the video, but rotations only work if I disable going to full screen here is part of my code
- (void)deviceOrientationDidChangeNotification:(NSNotification *)aNotification
{
switch ([[UIDevice currentDevice] orientation])
{
case UIDeviceOrientationPortrait:
case UIDeviceOrientationPortraitUpsideDown:
[self setFullscreen:NO animated:YES];
break;
case UIDeviceOrientationLandscapeLeft:
case UIDeviceOrientationLandscapeRight:
[self.moviePlayerController play];
[self setFullscreen:YES animated:YES];
break;
default:
break;
}
}
- (void)setFullscreen:(BOOL)aFullScreen animated:(BOOL)anAnimated
{
if( aFullScreen )
{
switch ([[UIDevice currentDevice] orientation])
{
case UIDeviceOrientationLandscapeLeft:
case UIDeviceOrientationPortraitUpsideDown:
self.moviePlayerController.view.transform = CGAffineTransformMakeRotation(M_PI_2);
break;
case UIDeviceOrientationPortrait:
case UIDeviceOrientationLandscapeRight:
self.moviePlayerController.view.transform = CGAffineTransformMakeRotation(M_PI+M_PI_2);
break;
default:
break;
}
}
else
self.moviePlayerController.view.transform = CGAffineTransformMakeRotation(0);
[self.moviePlayerController setFullscreen:aFullScreen animated:anAnimated]; // comment this out and rotation works
}
Can anybody give any advice, I am now think I should implement my own transition to full screen to get it to work, but I thought I would get some feedback first.
I’ve been flummoxed by this, too … wrestled with device and view rotations and whatnot, and even managed to get things mostly working, but I was continually finding one more case that would spoil it (e.g. user going in and out of full screen while rotated, mysteriously losing the status bar after playback, and so on).
I hope you can find a solution along the lines you’ve suggested here (and I look forward to learning from it). Otherwise, you can do what I did, snatching semi-victory from the jaws of semi-defeat as follows:
playing. It allows landscape orientation simply by answering
shouldAutorotateToInterfaceOrientation:
and simply presentModalViewController: on the new one. (You can even
have a cool freebie transition effect, like a vertical slide in).
MPMoviePlayerPlaybackDidFinishNotification, on notify, do [self
dismissModalViewController:YES];
A side benefit of all this is that the movie player handling logic can get dumped in one place and easily reused in your app.
Good luck. (I can provide detailed code if you need it).