MPMoviePlayerController full screen orientation issue

心已入冬 提交于 2020-01-07 02:56:09

问题


My app supports only Landscape. I've added an MPMoviePlayerController to the view of my view controller.

When I press full screen button, it works fine and it will rotate in Landscape only for iOS versions prior to iOS 5. However, in iOS 5.0+, it also supports portrait (only when I enter into full screen mode).

How can I prevent portrait support in iOS 5.0 and above?


回答1:


Try subclassing MPMoviePlayerViewController and overriding the shouldAutorotatoToInterfaceOrientation method to only support landscape modes:

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



回答2:


I resolved this problem thus: create custom navigation controller what support 2 orientation: UIInterfaceOrientationLandscapeLeft && UIInterfaceOrientationLandscapeRight

More details: 1. Create custom navigation controller

CustomNavigationController.h file

#import <UIKit/UIKit.h>

@interface CustomNavigationController : UINavigationController

-(CustomNavigationController*)initWithRootViewController:(UIViewController *)rootViewController;

@end

CustomNavigationController.m file

@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.In Appdelegate add self navigation controller

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

And now you have app with two orientation and video in landscape orientation.



来源:https://stackoverflow.com/questions/10631997/mpmovieplayercontroller-full-screen-orientation-issue

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