سؤال

I realise this is a very common issue but none of the solutions I have found solve my problem.

To fix the crashing issue with Game Center when launched in landscape you must add the supported interface orientations for ALL orientations (which I have done). The crashing on iPhone/iPod has now been resolved for those specific devices.

Now, the issue I have is iPad 1 specific. If you hold the iPad in portrait mode upon game launch the game can stays in portrait till you rotate the device (if you then try rotate it back, it wont, it is only on STARTUP that I can get this issue to occur). Unless I remove portrait from supported interface orientations. Unfortunately if I do this, the app will crash on other devices.

My inital interface orientation is Landscape Left.

This is the code I currently have:

(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
{
    return (toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft || toInterfaceOrientation == UIInterfaceOrientationLandscapeRight);
}

- (NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskLandscapeRight|UIInterfaceOrientationMaskLandscapeLeft;
}


- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
    return UIInterfaceOrientationLandscapeRight;
}

- (BOOL)shouldAutorotate{
    return YES;
}
هل كانت مفيدة؟

المحلول

Try this in appDelegate:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    UIInterfaceOrientation orientation = [UIApplication sharedApplication].statusBarOrientation;
    if( orientation == UIDeviceOrientationPortrait || orientation == UIDeviceOrientationPortraitUpsideDown )
        [[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeRight];
}
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top