Ios – presentViewController changes the orientation of the controller


I want to play a video from a view controller. When I present it, it is presented like it is a portrait orientation, so view turns. It only happens on iPhones,not the iPads.

There is a ViewController > MyItemsController > VideoController

enter image description here

When I close the VideoController, parent controller (MyItemsController) of the video controller is like:

enter image description here

Storyboard of the view controller is:

enter image description here

And the code is:

-(void)playMoviesForItems:(NSArray *)shopItems{
    VideoPlayerViewController* moviePlayer = [self.storyboard instantiateViewControllerWithIdentifier:@"videoPlayerController"];
    moviePlayer.modalPresentationStyle = UIModalPresentationCurrentContext;
    moviePlayer.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
    [self presentViewController:moviePlayer animated:NO completion:nil];

I moved the code into app delegate :

-(void)playMoviesForItems:(NSArray *)shopItems{
VideoPlayerViewController* mp = [[self getStoryboard] instantiateViewControllerWithIdentifier:@"videoPlayerController"];
[mp playMoviesForItems:shopItems];
[self pauseBackgroundMusic];

[self.window makeKeyAndVisible];
[self.window.rootViewController presentViewController:mp animated:YES completion:NULL];

This time, everything seem to be ok. Movie is playing, I can hear the sound, but cannot see the video. Why?
enter image description here

Best Solution

While the accepted answer was down voted since it does not answer the question, here's something that works on iOS9 :

The method that gets called when the ViewController is presented (modally) is preferredInterfaceOrientationForPresentation. This method must return an orientation.
You should check the presenter's orientation and return it as preferred:

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
        UIInterfaceOrientation topOrientation = self.navigationController.visibleViewController.interfaceOrientation;
        UIInterfaceOrientation presentingOrientation = self.presentingViewController.interfaceOrientation;

        return   presentingOrientation ? presentingOrientation : topOrientation ? topOrientation : UIInterfaceOrientationLandscapeLeft;

topOrientation contains the visible view controller's orientation, while the presentingOrientation is the orientation of the called to presentViewController:animated... In general, I advise you to create a "base" UIViewController class, and inherit from it. This way all of your view controllers will benefit from this code.

Related Question