【问题标题】:iOS Status Bar covering UINavigationBar after playing embedded video in landscape [duplicate]在横向播放嵌入式视频后,iOS状态栏覆盖UINavigationBar [重复]
【发布时间】:2016-03-16 07:51:47
【问题描述】:

我正在使用 Objective-C 开发 iOS 应用程序。在发布时运行最新的 xCode (7.1.1) 并在 iOS 9.1 模拟器和 iPhone 6 上运行。

我的应用被锁定为纵向。应用程序的 1 部分有一个 UIWebView。 UIWebView 可以嵌入视频。当用户播放视频时,它允许他们将设备旋转到横向(这是预期的行为)。但是,一旦他们这样做并单击视频上的“完成”,状态栏就会开始与导航栏重叠(参见链接的屏幕截图)。

Status Bar overlapping UINavigationBar

在应用程序的其他地方,我本机呈现 MPMoviePlayerViewController,旋转对状态或导航栏没有影响。

有什么想法吗?

【问题讨论】:

    标签: ios objective-c uiwebview uiinterfaceorientation


    【解决方案1】:

    这里的问题是当您在 UIView 中移动时正确处理设备旋转。这在视频播放中很常见,其中视频需要横向但其他所有内容都是纵向的。这里有几个不错的链接:Forcing landscape orientation on fullscreen MPMoviePlayerController prevents correct rotation when exiting fullscreenWhat is the "right" way to handle orientation changes in iOS 8?。 Bob McCune 编写了 Learning AV Foundation 的书,并在他的 github repo https://github.com/bobmccune 上有一些很好的示例代码。如果您需要有关示例代码的更多详细信息,请告诉我,我可以提供其他链接。

    作为一个简单的快速修复,您可以尝试删除状态栏的显示,但这不合适。

    如果您需要,我可以发布更多示例代码链接,以便您了解这是如何完成的。如果您不提供一些代码,这可能是最好的方法。

    【讨论】:

    【解决方案2】:
    - (void)viewDidLoad {
    
        self.navigationBarCenterY = self.navigationController.navigationBar.center.y;
        [[NSNotificationCenter defaultCenter] addObserver:self
                                                 selector:@selector(handleWindowDidBecomeHiddenNotification:)
                                                     name:UIWindowDidBecomeHiddenNotification
                                                   object:self.view.window];
    }
    
    - (void)handleWindowDidBecomeHiddenNotification:(NSNotification *)notify
    {
        if (self.navigationController.navigationBar.center.y != self.navigationBarCenterY) {
            self.navigationController.navigationBar.center = CGPointMake(self.navigationController.navigationBar.center.x, self.navigationBarCenterY);
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-07-09
      • 1970-01-01
      • 2014-05-27
      • 1970-01-01
      • 1970-01-01
      • 2014-02-22
      • 1970-01-01
      相关资源
      最近更新 更多