Bug in iOS 6 after adding GameCenter to cocos2d terrain-only app

I have the problem described here: https://devforums.apple.com/thread/165384?tstart=0 In case of an app crashing trying to load the GameCenter login screen because the screen is in portrait and my app only supports landscape. I have tried all the solutions in the above thread, as well as all the solutions in the following thread: Failure to present UIImagePickerController in iOS 6.0 And here: http://www.cocos2d-iphone.org/forum/topic/36639

None of the solutions work. Any crash still happens, or login works fine and my app then rotates freely between landscape and portrait, or it locks into portrait and spins the whole UI.

I want the GameCenter login to work in portrait and then for everything else in the app to happen in landscape.

Here are all the rotation methods contained in my application. These are those from the implementation of myNavigationController in appdelegate.m:

    -(NSUInteger)supportedInterfaceOrientations {

    // iPhone only
    if( [[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone )
        return UIInterfaceOrientationMaskLandscape;

    // iPad only
    return UIInterfaceOrientationMaskLandscape;
}


- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // iPhone only
    if( [[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone )
        return UIInterfaceOrientationIsLandscape(interfaceOrientation);

    // iPad only
    // iPhone only
    return UIInterfaceOrientationIsLandscape(interfaceOrientation);
}


-(BOOL)shouldAutorotate{

    return NO;
 }

      

And from the AppController implementation in appDelegate.m:

    - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return UIInterfaceOrientationIsLandscape(interfaceOrientation);
}

      

Contained in RootViewController.m:

    -(BOOL)shouldAutorotate{
        return NO;
}

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


- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
    return UIInterfaceOrientationLandscapeRight;
}


- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
        return NO;
    }


#if GAME_AUTOROTATION==kGameAutorotationNone
    return ( interfaceOrientation == UIInterfaceOrientationPortrait );

#elif GAME_AUTOROTATION==kGameAutorotationCCDirector
    if( interfaceOrientation == UIInterfaceOrientationLandscapeLeft ) {
        [[CCDirector sharedDirector] setDeviceOrientation: kCCDeviceOrientationLandscapeRight];
    } else if( interfaceOrientation == UIInterfaceOrientationLandscapeRight) {
        [[CCDirector sharedDirector] setDeviceOrientation: kCCDeviceOrientationLandscapeLeft];
    }


#elif GAME_AUTOROTATION == kGameAutorotationUIViewController
#else
#error Unknown value in GAME_AUTOROTATION

#endif // GAME_AUTOROTATION
    // Shold not happen
    return NO;
}

kGameAutorotationUIViewController

#if GAME_AUTOROTATION == kGameAutorotationUIViewController
-(void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{

    CGRect screenRect = [[UIScreen mainScreen] bounds];
    CGRect rect = CGRectZero;

    if(toInterfaceOrientation == UIInterfaceOrientationPortrait || toInterfaceOrientation == UIInterfaceOrientationPortraitUpsideDown)
        rect = screenRect;

    else if(toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft || toInterfaceOrientation == UIInterfaceOrientationLandscapeRight){
        rect.size = CGSizeMake( screenRect.size.height, screenRect.size.width );
    }


    CCDirector *director = [CCDirector sharedDirector];
    UIView *glView = [[CCDirector sharedDirector] view];;
    float contentScaleFactor = [director contentScaleFactor];

    if( contentScaleFactor != 1 ) {
        rect.size.width *= contentScaleFactor;
        rect.size.height *= contentScaleFactor;
    }
    glView.frame = rect;
}
#endif // GAME_AUTOROTATION == kGameAutorotationUIViewController

      

+1


source to share


1 answer


Just answered this question a few days ago here: Cocos 2d 2.0 shouldAutorotate not working?



There are instructions on what you need to do to get this to work in this answer. Hope this helps!

+2


source







All Articles