将GameCenter添加到仅景观cocos2d应用程序后,iOS 6中出现错误

问题描述:

我遇到这里所述的问题:
https:// devforums .apple.com / thread / 165384?tstart = 0
我的应用程序崩溃,试图加载GameCenter登录屏幕,因为屏幕是纵向的,我的应用程序只支持横向。
我试过了上面的线程中描述的每个解决方案,以及下面线程中的所有解决方案:
在ios6下呈现UIImagePickerController时出错
在这里:
http://www.cocos2d-iphone.org/forum/topic/36639

I'm having the issue described here: https://devforums.apple.com/thread/165384?tstart=0 Where my app crashes trying to load the GameCenter login screen because the screen is in portrait and my app only supports landscape. I've tried every solution described in the above thread, as well as all the solutions on the following thread: Crash on presenting UIImagePickerController under ios6 And here: http://www.cocos2d-iphone.org/forum/topic/36639

没有解决方案工作。或者崩溃仍然发生,或者登录工作正常,我的应用程序然后在景观和肖像之间*旋转,或者将自己锁定为肖像和拧紧整个UI。

None of the solutions work. Either the crash still occurs, or the login works fine, and either my app then freely rotates between landscape and portrait, or it locks itself into portrait and screws up the entire UI.

我想要的是让GameCenter登录以纵向方式工作,然后在应用程序中的其他所有内容都在横向上发生。

What I want is for the GameCenter login to work in portrait, and then for everything else in the app to occur in landscape.

这里是所有的旋转方法在我的应用程序。这些是来自appdelegate.m中的myNavigationController实现的那些:

Here are all the rotation methods contained in my app. These are the ones from the myNavigationController implementation 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;
 }

从appDelegate.m中的AppController实现:

And from the AppController implementation in appDelegate.m:

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

包含在RootViewController.m中:

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


几天前在这里回答这个问题:
Cocos 2d 2.0 shouldAutorotate不工作?

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 that answer. Hope this helps!