I am using xcdYoutubeVideoViewController which is subclassed from MPMoviePlayerController. My application is in portrait. To launch the movieplayer, I am doing this:
UINavigationController *navBarController = (UINavigationController*)[[[UIApplication sharedApplication] keyWindow] rootViewController] ;
[navBarController presentMoviePlayerViewControllerAnimated:vc];
where vc is instance of XCDYouTubeVideoPlayerViewController. How can I allow rotation only in this view and on pressing done button in movieplayer bring the application back to portrait?
You should override: -(BOOL) shouldAutorotate
in each view controller. Return YES if you want that view controller to rotate NO otherwise. Be sure to check the supported orientation on your storyboard setting.
Update: In your parent controller that presents the player try this:
- (BOOL)shouldAutorotate
{
// 1. check if the parent presentedViewController is the nav containing the player
// 2. if yes, return YES, NO otherwise
}
If the app root controller is a Navigation Controller, subclass UINavigationViewController
and use that class in creating the app root view controller in App Delegate
@implementation ANavigationViewControllerSubClass
- (BOOL)shouldAutorotate
{
return [self.topViewController shouldAutorotate];
}
- (NSUInteger)supportedInterfaceOrientations
{
return [self.topViewController supportedInterfaceOrientations];
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
return [self.topViewController preferredInterfaceOrientationForPresentation];
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return [self.topViewController shouldAutorotateToInterfaceOrientation:interfaceOrientation];
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
return [self.topViewController preferredInterfaceOrientationForPresentation];
}