【问题标题】:My app starts upside down我的应用程序颠倒启动
【发布时间】:2011-12-09 12:32:48
【问题描述】:

我已经开发了一段时间并已发布游戏的引擎现在正在颠倒启动我当前的项目,并立即按照预期的方式旋转 UIView。我用代码创建了界面,这就是它的样子:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{    
    ...

    CGRect screenBounds = [[UIScreen mainScreen] applicationFrame]; 
    CGRect windowBounds = screenBounds; 
    windowBounds.origin.y = 0.0;
    UIWindow* win = [[UIWindow alloc] initWithFrame:windowBounds];  
    win.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;

    UIMyView* view = [[UIMyView alloc] initWithFrame:screenBounds]; 
    UIMyViewController* controller = [[UIMyViewController alloc] init]; 
    controller.view = view; 

    view.multipleTouchEnabled = true;   
    view.windowWrapper = this;  
    view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;

    [win addSubview:view];

    ...
}


- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation;
{
    s32 validOrientations = ((cViewMM*)(self.view)).windowWrapper->GetValidOrientations();
    if (toInterfaceOrientation == UIInterfaceOrientationPortrait && (validOrientations & 0x01))
        return true;

    if (toInterfaceOrientation == UIInterfaceOrientationPortraitUpsideDown && (validOrientations & 0x02))
        return true;

    if (toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft && (validOrientations & 0x04))
        return true;

    if (toInterfaceOrientation == UIInterfaceOrientationLandscapeRight && (validOrientations & 0x08))
        return true;

    return false;
}

仅当我想在 UIInterfaceOrientationLandscapeLeft 中启动应用程序时才会出现此问题。通过应用程序进行调试,当我尝试将视图添加到内部窗口时,应该多次调用 shouldAutorotateToInterfaceOrientation:。首先是返回 false 的 UIInterfaceOrientationPortrait,然后是返回 true 的 UIInterfaceOrientationLandscapeRight(因为它是有效的方向),然后是也返回 true 的 UIInterfaceOrientationLandscapeLeft(因为它是有效的方向并且它是设备的当前方向)。

哦,更具体地说,这只发生在 iPhone 上,而不是 iPad 上。他们使用相同的代码来设置此视图。

我做错了什么?

-- 编辑--

好的,我对 shouldAutorotateToInterfaceOrientation 的执行有误:它执行了 3 次,请求 UIInterfaceOrientationPortrait,2 次请求 UIInterfaceOrientationLandscapeLeft,然后一次请求 UIInterfaceOrientationLandscapeRight,再次请求 UIInterfaceOrientationLandscapeLeft。

GameCenter 已经在此时初始化,因为它正在推送一些额外的 UI,我认为可能是它,但事实并非如此。

【问题讨论】:

  • '我做错了什么?'不是站在你的头上? =]
  • 如果有帮助我会去做的。

标签: iphone ios orientation


【解决方案1】:

在您的 Info.plist 中检查支持的方向数组以纵向(右侧向上)开始。如果它以任何不同的方向启动,您的应用程序将以该方向启动。

【讨论】:

  • UIInterfaceOrientationLandscapeLeft、UIInterfaceOrientationLandscapeRight 都在我的 plist 中,并且按此顺序排列。我想支持两者,只是我希望初始方向是设备的方向。
  • 啊。嗯......我没有一个可靠的答案。如果您不显示状态栏,那么您可以让您的默认图像看起来像是纵向的,但这不是一个完整的解决方案。
【解决方案2】:

找到了解决办法!

显然 Interface Builder 中存在错误。如果您只是单击关闭所有方向,然后以正确构建 Info.plist 的所需顺序重新单击它们。

【讨论】:

  • 正如我所说的,所有的界面都是用代码创建的,我没有在这个项目中使用 Interface Builder。而且我认为问题不在 Info.plist 中,因为没有所需的顺序。我想同时支持 UIInterfaceOrientationLandscapeLeft 和 UIInterfaceOrientationLandscapeRight 两个方向。我只需要应用程序在启动应用程序时以设备所在的方向启动。
  • 问题不在于应用程序支持方向,问题在于模拟器本身倒置启动。我又破解了,模拟器肯定对 plist 中的顺序很敏感。
  • 我在 iPhone 上测试,而不是在模拟器上。
  • 倒置问题也出现在 iOS 设备上。如果顺序不正确,启动图片和状态栏将颠倒。就我而言,我在模拟器和 iOS 设备上的方向代码检测并纠正了视图。
  • 倒置问题也出现在 iOS 设备上。如果顺序不正确,启动图片和状态栏将颠倒。就我而言,我在模拟器和 iOS 设备上的方向代码检测并纠正了视图。
【解决方案3】:

在我的情况下,它像 tgunr 所说的那样工作,但我必须从模拟器文件夹中删除整个应用程序,否则,方向的改变不起作用。

【讨论】:

    【解决方案4】:

    我遇到了同样的问题,很遗憾看到它没有得到解决。然后我意识到一件关键的事情可以证明这就是事情的运作方式:Default.png 启动图像也是颠倒的。您无法在您的应用程序中执行任何操作来解决此问题。您可以选择正确启动哪种横向模式(左侧或右侧的主页按钮),但您不能让它们同时工作。

    【讨论】:

    • 是的,你对 default.png 的看法是正确的。它在 iPad 上运行良好。我相信这个问题在旧的iOS版本上也不存在(我实际上忘记了)。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-06-10
    • 1970-01-01
    • 1970-01-01
    • 2012-11-10
    • 1970-01-01
    • 2018-07-30
    相关资源
    最近更新 更多