Just My Life & My Work

我使用第三方套件XCDYouTubeKit,就可以透過內建的MPMoviePlayerViewController來播放影片,那麼想要在特定的畫面橫向怎麼實現?因為整個App專案設定只有Portrait,也就是直向,只有在播放影片時要變成可以Landscape,就是橫向。

[iOS] 播放影片時特定畫面橫向.jpg

先前寫了篇文章:在WebView播放Youtube影片旋轉,確實可以做到。不過iOS 9之後又有稍微變化,只好改寫它囉~

只要在AppDelegate.m實作如下:

/**
Theme: Display Video for Landscape
IDE: Xcode 9
Language: Objective C
Date: 106/12/28
Author: HappyMan
Blog: https://cg2010studio.com/
*/

-(UIInterfaceOrientationMask)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
if ([[window.rootViewController presentedViewController]
isKindOfClass:[MPMoviePlayerViewController class]] || [[window.rootViewController presentedViewController] isKindOfClass:NSClassFromString(@"MPInlineVideoFullscreenViewController")] || [[window.rootViewController presentedViewController] isKindOfClass:NSClassFromString(@"AVFullScreenViewController")]) {

return UIInterfaceOrientationMaskAllButUpsideDown;
}else {

if ([[window.rootViewController presentedViewController]
isKindOfClass:[UINavigationController class]]) {

// look for it inside UINavigationController
UINavigationController *nc = (UINavigationController *)[window.rootViewController presentedViewController];

// is at the top?
if ([nc.topViewController isKindOfClass:[MPMoviePlayerViewController class]]) {
return UIInterfaceOrientationMaskAllButUpsideDown;

// or it’s presented from the top?
} else if ([[nc.topViewController presentedViewController]
isKindOfClass:[MPMoviePlayerViewController class]]) {
return UIInterfaceOrientationMaskAllButUpsideDown;
}
}
}
return UIInterfaceOrientationMaskPortrait;
}

 

MPMoviePlayerViewController在iOS 9後已被棄用,目前我用Xcode 9.2會顯示黃色驚嘆號,看來未來有必要再次改寫!

Apple就是這樣,會跟著時代潮流來調整SDK,不過我們只要喜歡學習新資訊技術,就不用擔心會被時間沖淡價值。

參考:iOS9 supportedInterfaceOrientationsForWindow stops getting called

Comments on: "[iOS] 播放影片時特定畫面橫向" (1)

  1. […] 在播放影片時特定畫面橫向文章提到播放影片時要橫向,那麼在播放完影片後,想要回復到直向可以怎麼做? […]

隨意留個言吧:)~

在下方填入你的資料或按右方圖示以社群網站登入:

WordPress.com 標誌

您的留言將使用 WordPress.com 帳號。 登出 /  變更 )

Twitter picture

您的留言將使用 Twitter 帳號。 登出 /  變更 )

Facebook照片

您的留言將使用 Facebook 帳號。 登出 /  變更 )

連結到 %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

標籤雲

%d 位部落客按了讚: