LoginSignup
18
18

More than 5 years have passed since last update.

縦対応(Portrait)しかしていないアプリでUIWebViewで動画を再生したときに横回転(Landscape)するようにする

Last updated at Posted at 2014-06-08

ちなみに、今回はUITabBarController>UIWebViewなアプリケーションの場合です。

AppDelegate.m
// 回転時に呼ばれる
- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window {
    NSString *className = NSStringFromClass([window class]);

    // ネストしているViewがMPFullscreenWindowやMPInlineVideoFullscreenViewControllerである場合があるので確認する
    if ([((UITabBarController *)window.rootViewController) respondsToSelector:@selector(presentedViewController)]) {
        className = NSStringFromClass([((UITabBarController *)window.rootViewController).presentedViewController class]);
    }

    // MP*FullscreenWindowなどがYouTube再生時のViewの名称なので
    // そのときは全部の回転を許可する
    if ([className isEqualToString:@"MPFullscreenWindow"] || [className isEqualToString:@"MPInlineVideoFullscreenViewController"]) {
        return UIInterfaceOrientationMaskAll;
    } else {
        return UIInterfaceOrientationMaskPortrait;
    }
}

参考:
http://stackoverflow.com/questions/22095982/how-to-rotate-a-video-embed-in-uiwebview-for-ios-7-only

18
18
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
18
18