【问题标题】:iOS statusbar ignores supportedInterfaceOrientations in root controlleriOS状态栏忽略根控制器中的supportedInterfaceOrientations
【发布时间】:2014-05-15 11:11:09
【问题描述】:

我有一个应用程序需要一直处于纵向模式,播放视频时除外。为了在我的项目设置中为 VideoController 启用横向模式,我启用了所有支持的方向模式。 但是,这也允许我的其他控制器旋转。为了解决这个问题,我将以下内容添加到我的根目录UINavigationController

- (BOOL)shouldAutorotate
{
   return YES;
}

-(NSUInteger)supportedInterfaceOrientations
{
   if([[VideoPlaybackManager sharedManager] videoIsPlaying]) {
       return UIInterfaceOrientationMaskLandscape;
   }

   return UIInterfaceOrientationMaskPortrait;
}

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
    if([[VideoPlaybackManager sharedManager] videoIsPlaying]) {
        return UIInterfaceOrientationLandscapeLeft;
    }
    return UIInterfaceOrientationPortrait;
}

现在我有两个问题:

  1. 应用程序的正常屏幕遵守限制并保持纵向。然而,状态栏会改变方向,无论是否破坏 UI。如果设备以横向模式打开,我将在纵向屏幕上有一个横向状态栏。如何解决此问题以使状态栏保持原位?

  2. 我设置了视频播放时的首选横向方向。这不起作用,preferredInterfaceOrientationForPresentation 似乎根本没有被调用。我做错了什么还是我错过了什么?

更新 我修复了 1. 通过将以下内容添加到我的 AppDelegate:

- (NSUInteger)application:(UIApplication *)application   supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
    if([[VideoPlaybackManager sharedManager] videoIsPlaying]) {
        return UIInterfaceOrientationMaskAll;
    }

    return UIInterfaceOrientationMaskPortrait;
}

问题 2。但是仍然存在。当我开始播放视频时,它不会以横向开始。有什么想法吗?

任何帮助将不胜感激! 谢谢!

【问题讨论】:

  • 您是否尝试在视频未播放时从 shouldAutorotate 返回 NO 以保持您的状态栏方向?
  • 我刚试过,状态栏似乎没有受到影响 - 它再次改变方向。

标签: ios iphone objective-c ios7 screen-orientation


【解决方案1】:

AppDelegate.m 中的这段代码会有所帮助

- (UIInterfaceOrientationMask)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window {
    UIViewController *topScreen = self.window.rootViewController;
    while (topScreen.presentedViewController) {
        topScreen = topScreen.presentedViewController;
    }
    return topScreen.supportedInterfaceOrientations;
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-12-18
    • 1970-01-01
    • 2014-08-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多