2016-04-05 98 views
4

我正在使用自动布局,并在屏幕上创建AVPlayerViewController与主视图的一半大小。我正在使用UITabBarViewController和UINavigationController。该屏幕从UITabBarViewController的第一个子ViewController导航。代码是这样的..如何使用AVPlayerViewController以横向方向旋转屏幕?

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。即使我旋转手机,它仍然保持纵向。当全屏按钮被点击时,也没有调用委托方法。请我非常需要这个。详细解释我应该如何实现这一点。谢谢

+0

您是否找到解决方案? – karthikeyan

+0

我也面临同样的问题,你找到一个解决方案? – FelipeOliveira

回答

2

下面的代码添加到您的viewController与含有AVPlayerViewController

-(BOOL)shouldAutorotate{ 
    return YES; 
} 

-(UIInterfaceOrientationMask)supportedInterfaceOrientations{ 
    return UIInterfaceOrientationMaskAllButUpsideDown; 
} 

希望它可以帮助你。

+0

它没有帮助我。当这种方法supportedInterfaceOrientations调用?我已经使用TabBarViewController。这不是最顶级的ViewController。它是从顶级杠杆ViewController导航的。 –

+0

@HirenPrajapati你的'AVPlayerViewController'是添加了子视图还是呈现? – Vvk

+0

哦,我的坏。在我的项目中,我只启用了纵向视图。顺便说一句AVPlayerViewController作为子视图添加。从项目启用园景定位后,现在我只想在用户单击全屏按钮时更改方向。我怎样才能做到这一点?我做错了吗?仅仅因为一个屏幕应该打开横向定向支持?因为屏幕在每个ViewController中旋转。 –

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