0

我的应用只支持横向。我在视图控制器的视图中添加了一个 MPMoviePlayerController。

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

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

4

2 回答 2

0

我因此解决了这个问题:创建支持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];

现在你有两个方向和横向视频的应用程序。

于 2013-06-10T13:10:45.483 回答
0

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

-(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
{
    if((toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft) || (toInterfaceOrientation == UIInterfaceOrientationLandscapeRight))
    {
        return true;
    }
    else
    {
        return false;
    }    
}
于 2012-05-19T02:56:57.733 回答