【问题标题】:How to rotate screen in landscape orientation using AVPlayerViewController?如何使用 AVPlayerViewController 横向旋转屏幕?
【发布时间】:2016-04-05 04:51:43
【问题描述】:

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

【问题讨论】:

  • 你找到解决办法了吗?
  • 我也遇到了同样的问题,你找到解决办法了吗?

标签: ios objective-c xcode7 avplayer avplayerviewcontroller


【解决方案1】:

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

-(BOOL)shouldAutorotate{
    return YES;
}

-(UIInterfaceOrientationMask)supportedInterfaceOrientations{
    return UIInterfaceOrientationMaskAllButUpsideDown;
}

希望对你有帮助。

【讨论】:

  • 这对我没有帮助。这个方法supportedInterfaceOrientations什么时候调用?而且我使用过 TabBarViewController。而这还不是最顶级的ViewController。它是从顶部控制杆 ViewController 导航的。
  • @HirenPrajapati 你的AVPlayerViewController 是添加子视图还是显示?
  • 哦,我的错。在我的项目中,我只启用了纵向视图。 Btw AVPlayerViewController 被添加为子视图。从项目启用横向方向后,现在我只想在用户单击全屏按钮时更改方向。我怎样才能做到这一点?我做错了吗?仅仅因为一个屏幕我应该打开横向支持吗?因为屏幕在每个 ViewController 中都会旋转。
  • 所以在完全理解问题之后,现在我的问题是通过禁用项目中的横向支持,在 self.view 中添加的 AVPlayerViewController 如何在点击全屏按钮时旋转到横向?
  • 是的,这是从项目中禁用景观的正确方法。但我不明白你为什么要添加 AVPlayer 作为子视图?你为什么不介绍?你能帮我更好地理解你的问题吗
【解决方案2】:
-(UIInterfaceOrientationMask)supportedInterfaceOrientations{
    [avPlayerLayer removeFromSuperlayer];
    [avPlayerLayer setFrame:self.view.bounds];
    [self.view.layer addSublayer:avPlayerLayer];
    return UIInterfaceOrientationMaskAllButUpsideDown;
}

【讨论】:

    猜你喜欢
    • 2011-01-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-01-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-11-15
    相关资源
    最近更新 更多