【问题标题】:MPMoviePlayerController full screen orientation issueMPMoviePlayerController 全屏方向问题
【发布时间】:2012-05-17 08:08:50
【问题描述】:

我的应用仅支持横向。我已将 MPMoviePlayerController 添加到我的视图控制器的视图中。

当我按下全屏按钮时,它可以正常工作,并且它只会在 iOS 5 之前的 iOS 版本中以横向旋转。但是,在 iOS 5.0+ 中,它还支持纵向(仅当我进入全屏模式时)。

如何在 iOS 5.0 及更高版本中阻止纵向支持?

【问题讨论】:

    标签: iphone ios ipad ios5 mpmovieplayercontroller


    【解决方案1】:

    尝试继承 MPMoviePlayerViewController 并覆盖 shouldAutorotatoToInterfaceOrientation 方法以仅支持横向模式:

    -(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
    {
        if((toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft) || (toInterfaceOrientation == UIInterfaceOrientationLandscapeRight))
        {
            return true;
        }
        else
        {
            return false;
        }    
    }
    

    【讨论】:

    • 我正在使用 MPMoviePlayerController。我尝试使用 MPMoviePlayerController 的子类并覆盖 shouldAutorotatoToInterfaceOrientation 方法以仅支持横向。但是没用
    • MPMoviePlayerController 对于 iOS 5.0 已过时。您现在应该使用 MPMoviePlayerViewController(这是一个小区别,但请注意“控制器”之前的“视图”)并尝试从那里开始。
    【解决方案2】:

    我因此解决了这个问题:创建支持 2 方向的自定义导航控制器: UIInterfaceOrientationLandscapeLeft && UIInterfaceOrientationLandscapeRight

    更多详情: 1. 创建自定义导航控制器

    CustomNavigationController.h 文件

    #import <UIKit/UIKit.h>
    
    @interface CustomNavigationController : UINavigationController
    
    -(CustomNavigationController*)initWithRootViewController:(UIViewController *)rootViewController;
    
    @end
    

    CustomNavigationController.m 文件

    @implementation IORNavigationController
    
    -(CustomNavigationController*)initWithRootViewController:(UIViewController *)rootViewController
    {
        self = [super initWithRootViewController:rootViewController];
    
        if (self)
        {
        }
    
        return self;
    }
    
    - (void)viewDidLoad
    {
        [super viewDidLoad];
    }
    
    
    - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
    {
        return UIInterfaceOrientationIsLandscape(interfaceOrientation);
    }
    
    
    - (void)didReceiveMemoryWarning
    {
        [super didReceiveMemoryWarning];
    }
    
    @end
    

    2.在Appdelegate中添加自导航控制器

    Appdelegate.h

    @property (nonatomic, retain) CustomNavigationController*  navigationController;
    

    Appdelegate.m

    self.navigationController = [[[CustomNavigationController alloc] initWithRootViewController:start] autorelease];
    
    self.navigationController.view.autoresizesSubviews = YES;
    
    window.rootViewController = self.navigationController;
        [self.navigationController setNavigationBarHidden:YES];
    

    现在您的应用具有两个方向和横向视频。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多