MPMoviePlayerController does not change Orientation in full-Screen mode in iOS 5

岁酱吖の 提交于 2019-12-13 04:53:23

问题


In my app i support only portrait mode and use UINavigationController as RootViewController. But when i am playing movie using MPMoviePlayerController and Player is Fullscreen than i want it to support both landscape mode Also.

Does this using this great code by @ChrisBallinger this in iOS6 but its not working in iOS5 After long search on google i am not able to find the solution so posted here. Please help with this problem.

I have also tried to subclassing the navigationcontroller and set the Rotate code it found here but no luck.


回答1:


My sandbox app: https://github.com/comonitos/programatical_device_orientation

The solution is easy:

in interface (h file) :

    BOOL rotated;

in implementation (m file): 1. rewrite

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

2 call [self setup]

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



回答2:


what you will have to do is...

first implement notification in viewdidload method like below...

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

Now implement that rotate method like below..

 #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;
}
}

let me know it is working or not!!!

Happy Coding!!!



来源:https://stackoverflow.com/questions/18654670/mpmovieplayercontroller-does-not-change-orientation-in-full-screen-mode-in-ios-5

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