4

我正在使用自动布局,并在屏幕中创建了主视图一半大小的 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 附带的全屏按钮时,我希望视频在横向视图中旋转。即使我旋转手机,它也只是保持纵向。当点击全屏按钮时,也没有调用委托方法。请我非常需要这个。详细解释我应该如何实现这一点。谢谢

4

2 回答 2

2

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

-(BOOL)shouldAutorotate{
    return YES;
}

-(UIInterfaceOrientationMask)supportedInterfaceOrientations{
    return UIInterfaceOrientationMaskAllButUpsideDown;
}

希望对您有所帮助。

于 2016-04-05T05:13:29.817 回答
1
-(UIInterfaceOrientationMask)supportedInterfaceOrientations{
    [avPlayerLayer removeFromSuperlayer];
    [avPlayerLayer setFrame:self.view.bounds];
    [self.view.layer addSublayer:avPlayerLayer];
    return UIInterfaceOrientationMaskAllButUpsideDown;
}
于 2016-08-30T13:56:26.177 回答