ios - 如何使用 AVPlayerViewController 横向旋转屏幕?

标签 ios objective-c xcode7 avplayer avplayerviewcontroller

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

最佳答案

将以下代码添加到包含 AVPlayerViewControllerviewController

-(BOOL)shouldAutorotate{
    return YES;
}

-(UIInterfaceOrientationMask)supportedInterfaceOrientations{
    return UIInterfaceOrientationMaskAllButUpsideDown;
}

希望对你有帮助。

关于ios - 如何使用 AVPlayerViewController 横向旋转屏幕?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36417368/

相关文章:

ios - NSDate 变成 NSNumber MYSTERY

ios - Swift:计算属性的属性观察者

Objective-C:关联对象行为

ios - 隐藏分段索引上的搜索栏为 1

iphone - ImagePicker 中的 View 层次问题

git - 如何将 pods 项目检查到与主项目 xcode 7 相同的存储库中?

swift - : and = 之间的差异

ios - zRotation与移动不协调

ios - 如果我们可以使用 segues 返回到任何 View Controller ,为什么我们还要使用 unwind segue?

iphone - 在 iOS 5 上使用 ARC 过早发布对象?