【问题标题】:How to make uiwebview youtube video in landscape orientation when viewcontroller in portrait纵向视图控制器时如何以横向制作uiwebview youtube视频
【发布时间】:2013-12-17 20:31:19
【问题描述】:

我在 UIWebView 中使用嵌入式 youtube,我的视图控制器处于纵向模式,但我无法在全屏横向模式下看到视频。我尝试了 Stackoverflow 的许多解决方案,但没有一个适用于 iOS 7。

【问题讨论】:

    标签: objective-c xcode uiwebview uiinterfaceorientation


    【解决方案1】:

    当我遇到与你类似的问题时,我所做的是:

    1. 即使是纵向的,你也可以获得设备 方向。
    2. 如果方向是横向,您可以通过旋转来变换状态栏,与 MPMoviePlayerController 相同。

    这是我使用的代码(虽然它适用于 iOS6,所以可能会有所不同

    -(void) receivedRotate: (NSNotification*) notification
    {
        UIViewController *topController = [UIApplication sharedApplication].keyWindow.rootViewController;
        //Using this part to find the view controller on top (the one that's showing the video in fullscreen).
    
        while (topController.presentedViewController) {
            topController = topController.presentedViewController;
        }
    
        //After a little testing, the class of that controller is MPInlineVideoFullscreenViewController
        if ([topController isKindOfClass:NSClassFromString(@"MPInlineVideoFullscreenViewController")]) {
            topController.view.transform = CGAffineTransformMakeRotation(M_PI_2);
    
            //The 20 and -20 are to prevent the movie from going over the status bar
            topController.view.frame = CGRectMake(0, 20, self.view.frame.size.width,self.tabBarController.view.frame.size.height - 20);
        }
    }
    

    【讨论】:

    • 这是行不通的,因为你没有努力去理解你必须做什么。您应该学习如何调试项目(在这种情况下,我 100% 确定您甚至没有查看此功能是否正在执行)
    • 没有。您应该添加旋转手势通知识别器。
    • thanx @LordZsolt NSClassFromString(@"MPInlineVideoFullscreenViewController") 为我工作...
    【解决方案2】:
    - (void)viewDidLoad {
        [super viewDidLoad];
        // Do any additional setup after loading the view.
    
    
        [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(receivedRotate:) name:UIDeviceOrientationDidChangeNotification object:nil];
    }
    
    - (void)dealloc{
    
        [[NSNotificationCenter defaultCenter]removeObserver:self];
    }
    
    -(void) receivedRotate: (NSNotification*) notification
    {
    
    
            UIViewController *topController = [UIApplication sharedApplication].keyWindow.rootViewController;
            //Using this part to find the view controller on top (the one that's showing the video in fullscreen).
    
            while (topController.presentedViewController) {
                topController = topController.presentedViewController;
            }
    
    
    
            if ([topController isKindOfClass:NSClassFromString(@"AVFullScreenViewController")]) {
    
                switch ([UIDevice currentDevice].orientation) {
                    case UIDeviceOrientationFaceUp:
                        NSLog(@"UIDeviceOrientationFaceUp");
                        break;
                    case UIDeviceOrientationFaceDown:
                        NSLog(@"UIDeviceOrientationFaceDown");
                        break;
                    case UIDeviceOrientationLandscapeLeft:
                        NSLog(@"UIDeviceOrientationLandscapeLeft");
                        topController.view.transform = CGAffineTransformMakeRotation(M_PI_2);
                        break;
                    case UIDeviceOrientationLandscapeRight:
                        NSLog(@"UIDeviceOrientationLandscapeRight");
                        topController.view.transform = CGAffineTransformMakeRotation(-M_PI_2);
                        break;
                    default:
                        break;
                }
    
    
                topController.view.frame = CGRectMake(0, 0, [[UIScreen mainScreen] bounds].size.width,[[UIScreen mainScreen] bounds].size.height);
            }
    
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-12-21
      • 1970-01-01
      • 1970-01-01
      • 2013-01-15
      • 1970-01-01
      • 2011-09-08
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多