Search code examples
iosobjective-cmpmovieplayercontrolleruiinterfaceorientation

Error when dismissing a MPmovieViewController in landscape to a view in portrait only (UIApplicationInvalidInterfaceOrientation)


I'm creating an xcode application for IOS7 that work in portrait mod in most views.

The project setting allows "Portrait" "Landscape Left" and "Landscape Right".

In views that I only want to appears in portrait i add the following code to lock them in portrait mode :

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

-(BOOL)shouldAutorotate
{
    return NO;
}

-(NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskPortrait;
}

In one of these locked views i present a MPmovieViewController using the following code :

MPMoviePlayerViewController *movieViewController = [[MPMoviePlayerViewController alloc] initWithContentURL:replayURL];
    movieViewController.moviePlayer.scalingMode = MPMovieScalingModeAspectFit;

    [self presentMoviePlayerViewControllerAnimated:movieViewController];

This code create a MPmovieViewController that i can use in Portrait and Landscape. (that's what i want)

The problem appears when i press the done button of the MPMovieViewController to dismiss the MovieController when in landscape mode. The previous view doesn't support the landscape mode so i have the following error :

 *** Terminating app due to uncaught exception 'UIApplicationInvalidInterfaceOrientation', reason: 'preferredInterfaceOrientationForPresentation must return a supported interface orientation!'

How can i force the rotation back to portrait mode when dismiss MPMovieViewController?

Best regards

Richard


Solution

  • I'm answering myself. In fact it was very simple.

    Just add to the portrait only view :

    -(UIInterfaceOrientation)preferredInterfaceOrientationForPresentation { return UIInterfaceOrientationPortrait; }
    

    Thanks