My app starts upside down

≯℡__Kan透↙ 提交于 2019-12-12 14:20:52

问题


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;
}

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).

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

What am I doing wrong?

-- EDIT --

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 is alreay initializing at this point and since it's pushing some extra UI I thought it may be it, but it wasn't.


回答1:


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.




回答2:


I was having this same problem and was sad to see it unanswered. Then I realized one key thing that proves this is just how things work: the Default.png startup image is upside down as well. There is nothing you can do in your app to fix that. You can choose which landscape mode starts correctly (home button on left or right) but you can't make them BOTH work.




回答3:


Found the solution!

Evidently there is a bug in Interface Builder. If you simply click off all the orientations, then click them back on in the desired order the Info.plist is built correctly.




回答4:


In my case, it worked as tgunr said BUT I had to remove from simulator folder the whole app, otherwise, the change in orientation didn't work.



来源:https://stackoverflow.com/questions/7797953/my-app-starts-upside-down

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!