在iOS 5中,MPMoviePlayerController不会在全屏模式下更改Orientation

时间:2013-09-06 09:40:42

标签: iphone ios mpmovieplayercontroller

在我的应用中,我仅支持纵向模式,并使用UINavigationController作为RootViewController。但是当我使用MPMoviePlayerController播放电影而播放器是全屏时,我希望它同时支持landscape模式。

在iOS6中使用@ChrisBallinger this使用这个优秀的代码,但它在iOS5中不起作用吗?经过长时间搜索谷歌后,我无法找到这里发布的解决方案。请帮助解决这个问题。

我还试图对navigationcontroller进行子类化并将旋转代码设置为found here,但没有运气。

2 个答案:

答案 0 :(得分:1)

我的沙盒应用: https://github.com/comonitos/programatical_device_orientation

解决方案很简单:

接口(h文件)中的

    BOOL rotated;
实现中的

(m文件): 1.重写

    -(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
    {
    return rotated;
    }

2调用[自我设置]

    -(void) setup { 
    rotated = YES; 
    [[UIDevice currentDevice] setOrientation:UIDeviceOrientationLandscapeLeft]; 
    rotated = NO; 
    }

答案 1 :(得分:-1)

你将要做的是......

首先在viewdidload方法中实现通知,如下所示......

    [[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
[[NSNotificationCenter defaultCenter] addObserver:self
                                         selector:@selector(rotate:)
                                             name:UIDeviceOrientationDidChangeNotification
                                           object:nil];

现在实现如下旋转方法..

 #pragma mark - Rotate Screen Method
- (void)rotate:(NSNotification *)n {
//    if (!isFullScreen)
//        return;
switch ([[UIDevice currentDevice] orientation]) {
    case UIDeviceOrientationLandscapeLeft:
        playerView.transform = CGAffineTransformMakeRotation(M_PI / 2);//playerview is view in which  you have added MPMoviePlayerViewController object
        playerView.frame = CGRectMake(0, 0, 768, 1024);
        break;
    case UIDeviceOrientationLandscapeRight:
        playerView.transform = CGAffineTransformMakeRotation(-M_PI / 2);
        playerView.frame = CGRectMake(0, 0,768, 1024);
        break;
    case UIDeviceOrientationPortrait:
        playerView.transform = CGAffineTransformIdentity;
        playerView.frame = CGRectMake(0, 0, 768, 1024);
        break;
    case UIDeviceOrientationPortraitUpsideDown:
        playerView.transform = CGAffineTransformMakeRotation(M_PI);
        playerView.frame = CGRectMake(0, 0, 768, 1024);
        break;
    default:
        break;
}
}

让我知道它的工作与否!!!

快乐编码!!!