Reputation: 463
I have a MovieViewController as a child of UINavigationController. I used MPMoviePlayerViewController to play video streaming triggered from MovieViewController , and in that video view, it can change the orientation to landscape or portrait. All I need is, when I tap the done button the MovieViewController turn to portrait mode again because it's only support portrait mode.
Here is the code
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return UIInterfaceOrientationMaskPortrait;
}
- (NSUInteger) supportedInterfaceOrientations {
return(UIInterfaceOrientationMaskPortrait);
}
- (BOOL) shouldAutorotate {
return FALSE;
}
But when I tap the done button it's crashing, "preferredInterfaceOrientationForPresentation must return a supported interface orientation!"
note: I called the moviePlayer modally.
NSURL *movieURL = [NSURL URLWithString:@"URL"];
player =[[MyMoviePlayerViewController alloc]
initWithContentURL:movieURL];
[self presentViewController:player animated:YES completion:nil];
So after It is called, there is done button which will dismiss the view. The problem is when I view the movie in landscape mode and tap done button, it crashed because I only have 1 supported interface (portrait).
Upvotes: 0
Views: 1280
Reputation: 463
Thanks for all the answers but this is the code that solve all my problem above.
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
return UIInterfaceOrientationPortrait;
}
Upvotes: 0
Reputation: 5180
There's a few things you need to do.
First, remove this line - it's deprecated.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return UIInterfaceOrientationMaskPortrait;
}
Second, subclass your UINavigationController and add the following code:
- (NSUInteger)supportedInterfaceOrientations
{
NSUInteger orientation = UIInterfaceOrientationMaskPortrait;
if ([self.navigationController.visibleViewController isMemberOfClass:[MPMoviePlayerViewController class]]) {
orientation = UIInterfaceOrientationMaskAll;
}
return orientation;
}
- (BOOL)shouldAutorotate
{
return YES;
}
In this code, I assume you're pushing your MPMovieController (via your navigationController) on top of MovieViewController.
Upvotes: 2