如何仅旋转子类mpmovieplayer控制器并将其他视图固定为纵向

时间:2014-09-03 06:55:51

标签: ios objective-c orientation mpmovieplayercontroller

我使用的是xcdYoutubeVideoViewController,它是MPMoviePlayerController的子类。我的申请是纵向的。要启动电影播放器​​,我这样做:

UINavigationController *navBarController = (UINavigationController*)[[[UIApplication sharedApplication] keyWindow] rootViewController] ;
[navBarController presentMoviePlayerViewControllerAnimated:vc];

其中vc是XCDYouTubeVideoPlayerViewController的实例。如何才允许在此视图中旋转,并在电影播放器​​中按下完成按钮将应用程序恢复为肖像?

1 个答案:

答案 0 :(得分:2)

您应该在每个视图控制器中覆盖:-(BOOL) shouldAutorotate。如果您希望视图控制器旋转否则返回YES。请务必检查故事板设置中支持的方向。

更新:在显示播放器的父控制器中尝试以下操作:

- (BOOL)shouldAutorotate
{
     // 1. check if the parent presentedViewController is the nav containing the player

     // 2. if yes, return YES, NO otherwise
}

如果应用程序根控制器是导航控制器,则子类UINavigationViewController并使用该类在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]; 
}