2012-06-27 32 views
4

在iOS5的應用爲iPhone 4/4S我有一個UIViewController用的MPMoviePlayerController視圖添加到它的視圖:預防的MPMoviePlayerController旋轉和縮放爲縱向時在全屏

[self.view insertSubview:self.fullscreenMoviePlayerController.view atIndex:2]; 

的UIViewController中僅支持橫向:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation) interfaceOrientation 
{ 
    // Return YES for supported orientations. 
    return interfaceOrientation == UIInterfaceOrientationLandscapeLeft || 
      interfaceOrientation == UIInterfaceOrientationLandscapeRight; 

} 

這正確鎖定旋轉到只有景觀。但是,當我將MPVideoPlayerController設置爲全屏顯示時,忽略此視頻,並且視頻不再受風景限制,並旋轉至手機的任何方向。

如何防止MPMoviePlayerController的視頻旋轉至全屏的縱向方向?當手機旋轉到肖像時,視頻不旋轉至關重要。

我已經嘗試繼承MPVideoPlayerController並覆蓋shouldAutorotateToInterfaceOrientation:但這沒有效果。

MPMoviePlayerController只是視圖的一部分,所以使用MPMoviePlayerViewCotroller絕對不是一個選項。

+0

你究竟需要什麼,你總是在風景模式下的視頻播放?是的 – Ballu

+1

是的。我需要視頻僅在全屏顯示時才顯示。 – Undistraction

+0

你在iPad或iPhone上工作嗎? – marzapower

回答

2

如果你真的想避免使用MPMoviePlayerViewController,這似乎相當困難。 一個選項,即使在全屏模式下也能正常工作,那就是手動設置MPMoviePlayerController視圖的框架。 (請注意,在其他iOS問題中,有時使用背景視圖會產生不同的結果,但值得一試)。

MyMPMoviePlayerController.view.frame = CGRectMake(0, 0, your numbers, here); 

但是,蘋果在他們的文檔中說,控制器的框架應該設置爲其父視圖的框架。

[MyMPMoviePlayerController.view setFrame: parentView.bounds]; 

越少優雅的解決方案,但一個可能的工作,即使是一個沒有是這樣的:

監聽UIDeviceOrientationDidChangeNotification並採取電影播放器​​的看法。對它應用transfrom,bounds和center(或frame等),以使其仍然適合橫向視圖。每次嘗試旋轉時都基本上將其轉換回來。 (這都假設你真的無法阻止它與shouldAutorotateToInterfaceOrientation :)旋轉。

這裏唯一的問題是,它可能會保持縱向的電影,但螺旋與視圖,這不是預期的結果。

+0

謝謝這些是兩個很好的攻擊計劃。我之前走過類似的道路,很混亂,但看起來像這個問題沒有乾淨的解決方案。 – Undistraction

+0

只是一個想法...如果你有你的MPMoviePlayerController存儲在一個引用的某個地方,你可以將它添加到儘可能多的意見,你想。然後,您可以偵聽MPMoviePlayerWillEnterFullscreenNotification,並將添加到您的影片播放器(或可能是moviePlayer.view)的另一個視圖/ UIViewController(即禁用旋轉)添加到該視圖中,並且不允許旋轉。然後聽取相反的通知並駁回您的演示。 – ekinnear

+0

它看起來好像是可能的,但我已經能夠找到的最好方法是簡單地獲取設備旋轉通知,然後應用旋轉(並可能設置一個錨點,以便它將圍繞中心旋轉......)在必要時。顯然,忽略那些你不想旋轉的。通過接收有關全屏的通知,您可以根據電影的狀態單獨定義此行爲。 – ekinnear

-2

請訪問鏈接的鏈接,默認視頻顯示在影像模式只能在http://mobiledevelopertips.com/video/getting-mpmovieplayercontroller-to-cooperate-with-ios4-3-2-ipad-and-earlier-versions-of-iphone-sdk.html。我希望它能解決你的問題。

+0

此鏈接與我的問題無關,並且涉及iOS3。 – Undistraction

+0

但是你不需要關注SDK,只需檢查你在self.view上插入movieplyaer視圖,就像在這個例子中嘗試modalviewcontroller一樣,也許你可以完成你的工作。並感謝 - 我只是想幫助你的答案。 – Ballu

+1

我給你的答案投反對票,因爲1.你沒有回答這個問題,只是添加了一個鏈接。 2.該鏈接與我的問題無關。 – Undistraction

-1

您可以準備兩個視頻。如果沒有其他選擇。

+0

這不以任何方式回答我的問題。 – Undistraction

0

是的,我看到你所說的使用MPMoviePlayerViewController不是一個選項:

還是......爲什麼不嘗試讓你有,否則包含的MPMoviePlayerController,並在您的視圖控制器其它項目視圖控制器的MPMoviePlayerViewController。 MPMoviePlayerViewController已經內置了MPMoviePlayerController,你只需參考你自己的viewController中的MPMoviePlayerController,而不是MPMoviePlayerController。它具有您可以覆蓋的shouldAutorotateToInterfaceOrientation,並且應該爲您做正確的事情。

相關問題