将 GameCenter 添加到仅限横向的 cocos2d 应用程序后,iOS 6 出现错误 [英] Error in iOS 6 after adding GameCenter to a landscape-only cocos2d app

查看:29
本文介绍了将 GameCenter 添加到仅限横向的 cocos2d 应用程序后,iOS 6 出现错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了这里描述的问题:https://devforums.apple.com/thread/165384?tstart=0我的应用程序在尝试加载 GameCenter 登录屏幕时崩溃,因为屏幕是纵向的,而我的应用程序只支持横向.我已经尝试了上述线程中描述的所有解决方案,以及以下线程中的所有解决方案:在 iOS 6.0 下呈现 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 iOS 6.0 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!

这篇关于将 GameCenter 添加到仅限横向的 cocos2d 应用程序后,iOS 6 出现错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆