在景观中显示游戏中心模态视图

时间:2012-02-03 15:14:38

标签: iphone objective-c cocos2d-iphone modalviewcontroller game-center

我在仅横向方向使用cocos2d引擎,没有自动旋转。

我想显示标准GC成就模态视图。 它从屏幕的底部正常显示(在横向保持设备的同时),但它在屏幕的右侧消失(如肖像模态视图)。它似乎正在改变消除动画的方向,但在此之前视图不会旋转。它只是向右滑动。

我也在控制台收到警告:

Unbalanced calls to begin/end appearance transitions for <UIViewController: 0x41b9a0>.

这就是我展示这个控制器的方式:

-(void)showAchievements:(id) sender {

    utilityController = [[UIViewController alloc] initWithNibName:nil bundle:nil];
    [[[CCDirector sharedDirector] openGLView] addSubview:utilityController.view]; 

    GKAchievementViewController *achievements = [[GKAchievementViewController alloc] init];
    if (achievements != nil)
    {
        achievements.achievementDelegate = self;
        [utilityController presentModalViewController: achievements animated: YES];
    }
    [achievements release];
}

- (void)achievementViewControllerDidFinish:(GKAchievementViewController *)viewController
{
    [utilityController dismissModalViewControllerAnimated:YES];
    [utilityController release];
}

在gameConfig.h中我有以下配置:

#define GAME_AUTOROTATION kGameAutorotationNone

试图将此更改为kGameAutorotationCCDirector - 同样的事情。 kGameAutorotationUIViewController - uiviews在屏幕上跳跃。

请不要建议用CGAffineTransformMakeRotation旋转UIView - 这只是一个黑客......

3 个答案:

答案 0 :(得分:1)

对于Kobold2D,我使用category for the GKMatchmakerViewController为所有方向解决了这个问题。您可以为其他Game Center视图控制器创建相同的类别。

这将强制GC视图使用当前设备方向:

@implementation GKMatchmakerViewController (OrientationFix)
-(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // [RootViewController option removed for clarity]

    // all other autorotation types use the current device orientation
    ccDeviceOrientation orientation = [CCDirector sharedDirector].deviceOrientation;
    switch (interfaceOrientation)
    {
        case UIInterfaceOrientationPortrait:
            return (orientation == kCCDeviceOrientationPortrait);
            break;
        case UIInterfaceOrientationPortraitUpsideDown:
            return (orientation == kCCDeviceOrientationPortraitUpsideDown);
            break;
        case UIInterfaceOrientationLandscapeLeft:
            return (orientation == kCCDeviceOrientationLandscapeRight);
            break;
        case UIInterfaceOrientationLandscapeRight:
            return (orientation == kCCDeviceOrientationLandscapeLeft);
            break;
        default:
            break;
    }

    return NO;
}
@end

答案 1 :(得分:1)

这是我在Stackoverflow上的第一个答案,所以如果任何格式化可能无效,请原谅我。

无论如何,关于代码。对于Achievements-Viewcontroller,此解决方案适用于我。任何其他GK-Viewcontroller都可以相应地工作......

@implementation GKAchievementViewController (OrientationFix)

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

@end


@interface GKLeaderboardViewController (OrientationFix)

@end


-(void)showAchievements
{
    GKAchievementViewController *achievements = [[GKAchievementViewController alloc] init];

    if (achievements != nil)
    {
        achievements.achievementDelegate = self;
        [self presentModalViewController: achievements animated: YES];
    }

    [achievements release]; 
}

- (void)achievementViewControllerDidFinish: (GKAchievementViewController *)viewController 
{
    AppDelegate *delegate = [UIApplication sharedApplication].delegate; 
    [delegate.viewController dismissModalViewControllerAnimated:YES];
}

答案 2 :(得分:0)

尝试致电

     self.modalPresentationStyle = UIModalPresentationCurrentContext;

在呈现ViewController之前