【问题标题】:iOS portrait only app returns from UIWebview youtube in landscape仅 iOS 纵向应用程序从 UIWebview youtube 以横向返回
【发布时间】:2012-03-28 20:11:21
【问题描述】:

我正在创建一个iOS application,但遇到了以下问题:

项目设置为portrait 模式应用程序。 我有一个UIWebview,它会加载一个包含youtube 视频的网页。单击视频时,它会从youtube player 开始。当视频更改为landscape 模式并单击“完成”时,它会返回到UIWebview,在landscape 中显示它。

视频结束后我确实收到了NSNotification,但我无法强制使用portrait 模式。

这应该是不可能的,我怎样才能允许 youtube 处于 landscape 但强制应用程序保持 portrait 模式?还是有其他解决方法?

编辑:

与苹果联系后发现这是一个错误并被报告。

【问题讨论】:

  • 你是如何让 youtube 播放器从 UIWebView 以横向显示的?

标签: ios uiwebview youtube landscape-portrait


【解决方案1】:

我认为您可以按照您所说的使用 NSNotification 并在被调用的方法中暂时使用这行代码来强制视图显示为纵向

- (void)YourMethodCalledByNSNotification
{
    UIInterfaceOrientation orientation = [UIApplication sharedApplication].statusBarOrientation;

    if (orientation == UIInterfaceOrientationLandscapeLeft || orientation == UIInterfaceOrientationLandscapeRight || orientation == UIInterfaceOrientationPortraitUpsideDown) 
    {
        [[UIDevice currentDevice] setOrientation:UIInterfaceOrientationPortrait];
    }
}

希望有帮助

【讨论】:

    【解决方案2】:
    [[UIDevice currentDevice] setOrientation:UIInterfaceOrientationPortrait];
    

    是私有 API 。我不建议使用它。

        UIWindow *window = [[UIApplication sharedApplication] keyWindow];
        UIView *view = [window.subviews objectAtIndex:0];
        [view removeFromSuperview];
        [window insertSubview:view atIndex:0];
    

    我认为是更好的方式。它会强制应用调整其方向。

    【讨论】:

      猜你喜欢
      • 2013-01-23
      • 2012-09-26
      • 2013-07-14
      • 1970-01-01
      • 1970-01-01
      • 2014-10-25
      • 2014-09-16
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多