Ios 视频隐藏控制器的旋转

Ios 视频隐藏控制器的旋转,ios,mpmoviewcontroller,Ios,Mpmoviewcontroller,当我将视频从纵向旋转到横向时,它会以landscpae模式完全打开,但会隐藏视频控制器栏。我正在使用的代码: -(void) readyPlayer { mp = [[MPMoviePlayerViewController alloc] initWithContentURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"abc" ofType:@"mp4"]]]; [[NSNotific

当我将视频从纵向旋转到横向时,它会以landscpae模式完全打开,但会隐藏视频控制器栏。我正在使用的代码:

    -(void) readyPlayer
{
    mp = [[MPMoviePlayerViewController alloc] initWithContentURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"abc" ofType:@"mp4"]]];


    [[NSNotificationCenter defaultCenter] removeObserver:mp
                                                    name:MPMoviePlayerPlaybackDidFinishNotification
                                                  object:mp.moviePlayer];

    // Register this class as an observer instead
    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(movieFinishedCallback:)
                                                 name:MPMoviePlayerPlaybackDidFinishNotification
                                               object:mp.moviePlayer];

    // Set the modal transition style of your choice
    mp.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;

    mp.moviePlayer.scalingMode = MPMovieScalingModeAspectFit;

    for(UIView* subV in mp.moviePlayer.view.subviews) {
        subV.backgroundColor = [UIColor clearColor];
    }


    mp.moviePlayer.fullscreen=YES;
    [self.view addSubview:mp.view];
    [mp.moviePlayer play];

}
- (void)deviceOrientationDidChange:(NSNotification *)notification {


    UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation];
    CGRect screenRect = [[UIScreen mainScreen] bounds];
    CGFloat screenWidth = screenRect.size.width;
    CGFloat screenHeight = screenRect.size.height;
    rotation = 0;

    // Later we may handle the Orientation of Faceup to show a Map.  For now let's ignore it.

    if (orientation == UIDeviceOrientationPortrait) {
        {
            NSLog(@"portrait");
            [mp.view setFrame:CGRectMake(0,0,screenWidth,screenHeight)];
            rotation = 0;
            mp.view.transform = CGAffineTransformMakeRotation(rotation);
        }
    }

    else if (orientation != UIDeviceOrientationUnknown) {
        //CGRect bounds = [[UIScreen mainScreen] bounds];
        switch (orientation) {
            case UIDeviceOrientationLandscapeLeft:
            {
                              NSLog(@"Case 1");
                [mp.view setFrame:CGRectMake(0,0,screenWidth,screenHeight)];
                rotation = M_PI_2;  
                mp.view.transform = CGAffineTransformMakeRotation(rotation);
            }
                break;
            case UIDeviceOrientationLandscapeRight:
            {
                NSLog(@"Case 2");
               rotation = -M_PI_2;
                [mp.view setFrame:CGRectMake(0,0,screenWidth,screenHeight)];
                mp.view.transform = CGAffineTransformMakeRotation(rotation);
            }
                break;
            case UIDeviceOrientationPortraitUpsideDown:
            {
                NSLog(@"Case 3");
                rotation = -M_PI;
                [mp.view setFrame:CGRectMake(0,0,screenWidth,screenHeight)];
                mp.view.transform = CGAffineTransformMakeRotation(rotation);
            }
                break;


            default:
                break;
        }
    }
}

请提供帮助。

如果您的应用程序只需要支持纵向,并且所有视频都需要在两个方向播放,请执行以下步骤

1->项目文件->摘要->支持方向->勾选所有方向值的是

2->在根视图中,控制器实现(BOOL)应自动旋转并返回编号