2016-04-05 101 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; 
} 
相關問題