IOS6横向播放嵌入的youtube视频从uiwebview在一个唯一的肖像iPhone应用程序

IOS6横向播放嵌入的youtube视频从uiwebview在一个唯一的肖像iPhone应用程序,ios6,uiwebview,youtube,landscape,Ios6,Uiwebview,Youtube,Landscape,我有一个iPhone应用程序,它有一个故事板、几个xib和自定义单元格 应用程序被设置为“纵向”为“支持的界面方向”(我的意思是所有内容都是这样显示的)。 在我的自定义单元格中,有一个链接到youtube嵌入式视频的Uiwebview,当我单击它时,视频开始播放,但我的问题是它们总是以“纵向”模式播放。 我读过很多解决这个问题的东西,但只在ios5中读过 实际上: 我可以识别视频何时开始或停止播放。 我可以识别设备的方向。 但是我不能(我想要)将(强制)方向从纵向切换到横向,或者在用户改变设备方

我有一个iPhone应用程序,它有一个故事板、几个xib和自定义单元格

应用程序被设置为“纵向”为“支持的界面方向”(我的意思是所有内容都是这样显示的)。 在我的自定义单元格中,有一个链接到youtube嵌入式视频的Uiwebview,当我单击它时,视频开始播放,但我的问题是它们总是以“纵向”模式播放。 我读过很多解决这个问题的东西,但只在ios5中读过

实际上: 我可以识别视频何时开始或停止播放。 我可以识别设备的方向。 但是我不能(我想要)将(强制)方向从纵向切换到横向,或者在用户改变设备方向的情况下提出这种能力

提前谢谢


PS:如果需要,我可以显示用于识别应用程序的代码

我也有同样的问题。我的解决方案是:

1.首先打开xcode项目中的所有方向:

2.在AppDelegate.m中添加:

-(NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
    NSArray *stackViewControllers = self.navigationController.viewControllers;
    UIViewController *rvc = [stackViewControllers objectAtIndex:stackViewControllers.count - 1];

    if([rvc isKindOfClass:[VideoViewController class]])
    {
        id presentedViewController = [rvc presentedViewController];

        NSString *viewControllerName = NSStringFromClass([presentedViewController class]);
        if([viewControllerName isEqual:@"MPInlineVideoFullscreenViewController"] && [VideoViewController isVideoPlaying]) {
            return UIInterfaceOrientationMaskAll;
        }
    }
    return UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskPortraitUpsideDown;
}
在上面的代码中,每次系统要求支持的Interface Orientions for Window时,您都要检查当前的viewController是否在嵌入youtube播放器的
UIWebView
中,并且还要检查视频是否正在播放(即视频处于全屏模式)。
注意:我使用
UINavigationController
,如果不使用,则必须进行一些更改以获得当前的视图控制器。

3.在viewController中,我为youtube嵌入式播放器(在我的例子中是VideoViewController)放置了
UIWebView
,在它的头文件添加方法中:

+(BOOL)isVideoPlaying;

4.在VideoViewController.m中添加静态变量:

static BOOL _isVideoPlaying = NO;

5.在viewdiload中添加用于通知的addObserver,以便知道视频何时开始播放和是否将退出播放:

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(playerStarted:) name:@"UIMoviePlayerControllerDidEnterFullscreenNotification" object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(playerWillExitFullscreen:) name:@"UIMoviePlayerControllerWillExitFullscreenNotification" object:nil];

6.另外,添加通知选择器方法:

-(void)playerStarted:(NSNotification *)notification{
    _isVideoPlaying = YES;
}
-(void)playerWillExitFullscreen:(NSNotification *)notification {
    _isVideoPlaying = NO;

    if([AppUtils iOSVersion] < 6) //For iOS < 6.0, you must manually rotate viewController's view when fullscreen video playing is dismissed.
    {
        if ([[UIApplication sharedApplication] statusBarOrientation] == UIInterfaceOrientationLandscapeLeft || [[UIApplication sharedApplication] statusBarOrientation] == UIInterfaceOrientationLandscapeRight)
        {
            self.navigationController.view.userInteractionEnabled = NO;
            [UIView animateWithDuration:0.5 animations:^{
                [[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeLeft  animated:NO];
                // rotate main view, in this sample the view of navigation controller is the root view in main window
                [self.navigationController.view setTransform: CGAffineTransformMakeRotation(180 * M_PI * 0.5)];
                // set size of view
                [self.navigationController.view setFrame:CGRectMake(0, 0, 320, 960)];
            } completion:^(BOOL finished) {
                self.navigationController.view.userInteractionEnabled = YES;
            }];
        }
    }
}

所有这些技巧对我来说都很有效,支持iOS 5及更高版本。

希望它对你有用

我接受了阿尔马斯·阿迪尔贝克的回答(做得很好!),并将其归结为其基本组成部分。仅此代码(添加到我的应用程序代理中)似乎就能获得我想要的结果。将在遇到任何问题时更新

- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window {

    id presentedViewController = [window.rootViewController presentedViewController];
    NSString *className = presentedViewController ? NSStringFromClass([presentedViewController class]) : nil;

    if (window && [className isEqualToString:@"MPInlineVideoFullscreenViewController"]) {
        return UIInterfaceOrientationMaskAll;
    } else {
        return UIInterfaceOrientationMaskPortrait;
    }
}

非常感谢,它很有效。如果需要,我可以为任何人提供源代码。@user2587950你能给我发送这个演示项目吗?我遇到错误了?我不知道如何解决它。太棒了!谢谢:)工作正常,除非视频嵌入到模式中,并且在景观中忽略视频时有一个小错误。如果您这样做,那么界面就是横向的。要更正它,请添加以下测试:
[presentedViewController正在解除]==NO
THx以获取答案。但它在iOS7上对我不起作用
className
总是
RootViewController
。有什么想法吗?我将使用“isPlayingYoubeVideo”标志,但这不是很漂亮…在iOS 8上,检查AVFullScreenViewController而不是MPInLineVideoFullScreenViewController。在iOS 8上,我得到的是零presentedViewController。知道为什么吗?
- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window {

    id presentedViewController = [window.rootViewController presentedViewController];
    NSString *className = presentedViewController ? NSStringFromClass([presentedViewController class]) : nil;

    if (window && [className isEqualToString:@"MPInlineVideoFullscreenViewController"]) {
        return UIInterfaceOrientationMaskAll;
    } else {
        return UIInterfaceOrientationMaskPortrait;
    }
}