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
When I close the VideoController, parent controller (MyItemsController) of the video controller is like:
Storyboard of the view controller is:
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?
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:
topOrientation
contains the visible view controller's orientation, while thepresentingOrientation
is the orientation of the called topresentViewController: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.