avPlayerVideoController

avPlayerVideoController

我正在使用自动布局,并在屏幕上创建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附带的全屏按钮时,我希望视频以横向视图旋转。即使旋转手机,它也始终保持纵向。点击全屏按钮时也没有调用委托方法。拜托,我非常需要这个。详细说明我应该如何实现。谢谢

最佳答案

在包含viewControllerAVPlayerViewController中添加以下代码

-(BOOL)shouldAutorotate{
    return YES;
}

-(UIInterfaceOrientationMask)supportedInterfaceOrientations{
    return UIInterfaceOrientationMaskAllButUpsideDown;
}

希望对您有帮助。

07-27 22:30