How to rotate only the subclassed mpmovieplayer controller and keeping other views fixed to portrait

一笑奈何 提交于 2019-12-25 03:24:56

问题


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?


回答1:


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]; 
}


来源:https://stackoverflow.com/questions/25638064/how-to-rotate-only-the-subclassed-mpmovieplayer-controller-and-keeping-other-vie

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!