MPMoviePlayerController全屏方向问题

时间:2012-05-17 08:08:51

标签: iphone ios ipad ios5 mpmovieplayercontroller

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

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

如何防止iOS 5.0及更高版本中的肖像支持?

2 个答案:

答案 0 :(得分:0)

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

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

答案 1 :(得分: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];

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