将 GameCenter 添加到仅限横向的 cocos2d 应用程序后,iOS 6 出现错误

Error in iOS 6 after adding GameCenter to a landscape-only cocos2d app(将 GameCenter 添加到仅限横向的 cocos2d 应用程序后,iOS 6 出现错误)
本文介绍了将 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 出现错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Why local notification is not firing for UNCalendarNotificationTrigger(为什么没有为UNCalendarNotificationTrigger触发本地通知)
iOS VoiceOver functionality changes with Bundle Identifier(IOS画外音功能随捆绑包标识符而变化)
tabbar middle tab out of tabbar corner(选项卡栏中间的选项卡角外)
Pushing UIViewController above UITabBar(将UIView控制器推送到UITabBar上方)
How can I sync two flatList scroll position in react native(如何在本机Reaction中同步两个平面列表滚动位置)
Get an event when UIBarButtonItem menu is displayed(显示UIBarButtonItem菜单时获取事件)