我的应用程序开始颠倒了

Ale*_*eks 3 iphone orientation ios

我已经工作了一段时间并已发布游戏的引擎现在正在颠倒我的当前项目并立即按照它想象的方式旋转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;
}
Run Code Online (Sandbox Code Playgroud)

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

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

我究竟做错了什么?

- 编辑 -

好吧我对shouldAutorotateToInterfaceOrientation的执行错了:它执行3次要求UIInterfaceOrientationPortrait,2次执行UIInterfaceOrientationLandscapeLeft,然后执行一次UIInterfaceOrientationLandscapeRight,再次执行UIInterfaceOrientationLandscapeLeft.

GameCenter现在正在初始化,因为它正在推动一些额外的UI,我认为可能是它,但事实并非如此.

Joe*_*asq 25

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