Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/113.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c 将GameCenter添加到仅适用于横向的cocos2d应用程序后,iOS 6中出现错误_Objective C_Ios_Cocos2d Iphone_Orientation_Game Center - Fatal编程技术网

Objective c 将GameCenter添加到仅适用于横向的cocos2d应用程序后,iOS 6中出现错误

Objective c 将GameCenter添加到仅适用于横向的cocos2d应用程序后,iOS 6中出现错误,objective-c,ios,cocos2d-iphone,orientation,game-center,Objective C,Ios,Cocos2d Iphone,Orientation,Game Center,我在这里描述了这个问题: 我的应用程序在尝试加载GameCenter登录屏幕时崩溃,因为屏幕为纵向,我的应用程序仅支持横向。 我已经尝试了上述线程中描述的每个解决方案,以及以下线程中的所有解决方案: 在这里: 所有的解决方案都不起作用。要么崩溃仍在发生,要么登录工作正常,要么我的应用程序在横向和纵向之间自由旋转,要么它将自身锁定在纵向并破坏整个UI 我想要的是GameCenter登录在纵向模式下工作,然后应用程序中的所有其他内容都在横向模式下发生 以下是我的应用程序中包含的所有旋转方法。以下是

我在这里描述了这个问题: 我的应用程序在尝试加载GameCenter登录屏幕时崩溃,因为屏幕为纵向,我的应用程序仅支持横向。 我已经尝试了上述线程中描述的每个解决方案,以及以下线程中的所有解决方案: 在这里:

所有的解决方案都不起作用。要么崩溃仍在发生,要么登录工作正常,要么我的应用程序在横向和纵向之间自由旋转,要么它将自身锁定在纵向并破坏整个UI

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

以下是我的应用程序中包含的所有旋转方法。以下是appdelegate.m中myNavigationController实现中的内容:

    -(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;
 }
    - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return UIInterfaceOrientationIsLandscape(interfaceOrientation);
}
从appDelegate.m中的AppController实现:

    -(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;
 }
    - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return UIInterfaceOrientationIsLandscape(interfaceOrientation);
}
包含在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

几天前刚刚在这里回答了这个问题:


这里有一些说明,说明你需要做些什么才能让这个在那个答案中起作用。希望这有帮助

这很有效,谢谢!真希望在我花那么多时间检查其他三个线程中所有不起作用的东西之前,我已经找到了那个线程。