如何在viewcontroller中以横向方式制作uiwebview youtube视频

时间:2013-12-02 07:40:27

标签: objective-c xcode uiwebview uiinterfaceorientation

我在我的UIWebView中使用嵌入式youtube,我的viewcontroller处于纵向模式,但我无法在全屏风景中看到视频。我尝试了Stackoverflow的许多解决方案,但没有一个在iOS 7上运行。

2 个答案:

答案 0 :(得分:1)

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

  1. 即使它只是肖像,你也可以拿到设备     取向。
  2. 如果方向是横向的,您可以通过旋转来转换状态栏,并使用MPMoviePlayerController进行转换。
  3. 这是我使用的代码(虽然它适用于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);
        }
    }
    

答案 1 :(得分:0)

- (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);
        }

}