我的应用程序颠倒启动 [英] My app starts upside down

查看:85
本文介绍了我的应用程序颠倒启动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

一个我已经工作了一段时间并且已经发布游戏的引擎现在正在颠倒地启动我当前的项目,并且立即以预期的方式旋转了UIView.我用代码创建接口,这与它的外观有关:

An engine that I've worked on for a while and has shipped games is now launching my current project upside down and right away rotates the UIView the way it suppose to be. I create the interface with code and this is about how it looks like:

- (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:.首先是UIInterfaceOrientationPortrait,它返回false,然后是UIInterfaceOrientationLandscapeRight,它返回true(因为它是有效方向),然后是UIInterfaceOrientationLandscapeLeft,它也返回true(因为它是有效方向,它是设备的当前方向).

The problem occures only if I want to launch the application in UIInterfaceOrientationLandscapeLeft. Debugging through the application it looks like when I try to add my view to the window internally the shouldAutorotateToInterfaceOrientation: is called multiple times. First with UIInterfaceOrientationPortrait which returns false then UIInterfaceOrientationLandscapeRight which return true (since it's valid orientation) and then UIInterfaceOrientationLandscapeLeft which also returns true (since it's valid orientation and it's the current orientation of the device).

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

Oh and to be more specific this is happening only on iPhone not on iPad. They use the same code to setup this view.

我在做什么错了?

-编辑-

好的,我在执行shouldAutorotateToInterfaceOrientation时错了:它执行了3次要求UIInterfaceOrientationPortrait,两次执行UIInterfaceOrientationLandscapeLeft,然后一次要求UIInterfaceOrientationLandscapeRight,然后再次要求UIInterfaceOrientationLandscapeLeft.

OK I was wrong about the execution of shouldAutorotateToInterfaceOrientation: it is executed 3 times asking for UIInterfaceOrientationPortrait, 2 times for UIInterfaceOrientationLandscapeLeft, then once for UIInterfaceOrientationLandscapeRight, and again once UIInterfaceOrientationLandscapeLeft.

GameCenter目前正在初始化,并且由于它正在推送一些额外的UI,我认为可能是这样,但是事实并非如此.

GameCenter is alreay initializing at this point and since it's pushing some extra UI I thought it may be it, but it wasn't.

推荐答案

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

Check in your Info.plist that the array of supported orientations starts with portrait (right-side-up). If it starts with any different orientation your app will launch in that orientation.

这篇关于我的应用程序颠倒启动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆