首页 文章

如何使用AVPlayerViewController以横向方向旋转屏幕?

提问于
浏览
4

我正在使用autolayout并在屏幕上创建AVPlayerViewController,其大小是主视图的一半 . 我正在使用UITabBarViewController和UINavigationController . 此屏幕从UITabBarViewController的第一个子ViewController导航 . 代码是这样的..

avPlayerVideoController = [[AVPlayerViewController alloc] init];

    avPlayer = [AVPlayer playerWithURL:[NSURL URLWithString:videoURL]];

    avPlayerVideoController.view.frame = CGRectMake( imgViewVideo.frame.origin.x, imgViewVideo.frame.origin.y, imgViewVideo.frame.size.width, imgViewVideo.frame.size.height);
    avPlayerVideoController.delegate = self;
    avPlayerVideoController.showsPlaybackControls = YES;
    avPlayerVideoController.player = avPlayer;
    [avPlayerVideoController.player play];

现在,当我点击AVPlayerViewController附带的全屏按钮时,我希望视频在横向视图中旋转 . 即使我旋转手机,它仍然保持纵向 . 当点击全屏按钮时,也没有调用委托方法 . 请严格要求 . 详细解释我应该如何实现这一目标 . 谢谢

2 回答

  • 2

    将以下代码添加到 viewController 并包含 AVPlayerViewController

    -(BOOL)shouldAutorotate{
        return YES;
    }
    
    -(UIInterfaceOrientationMask)supportedInterfaceOrientations{
        return UIInterfaceOrientationMaskAllButUpsideDown;
    }
    

    希望它能帮到你 .

  • 1
    -(UIInterfaceOrientationMask)supportedInterfaceOrientations{
        [avPlayerLayer removeFromSuperlayer];
        [avPlayerLayer setFrame:self.view.bounds];
        [self.view.layer addSublayer:avPlayerLayer];
        return UIInterfaceOrientationMaskAllButUpsideDown;
    }
    

相关问题