【问题标题】:Displaying Game Center modal view in landscape横向显示 Game Center 模式视图
【发布时间】:2012-02-03 15:14:37
【问题描述】:

我在横向使用 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 - 这只是一个 hack...

【问题讨论】:

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


    【解决方案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
    

    【讨论】:

    • 感谢您的回答,但这个方向修复对我来说不适用于 GKAchievementViewController。此视图在启动和关闭后仍会从底部向上滑动 - 移至屏幕右侧。
    • 提醒一下,此示例代码适用于 GKMatchmakerViewController。您确定为 GKAchievementViewController 修改了吗?
    • 是的,当然.. 这次让它以这种方式工作。稍后会调查。
    【解决方案2】:

    这是我在 Stackoverflow 上的第一个答案,如果任何格式可能不起作用,请原谅我。

    不管怎样,进入代码。该解决方案适用于我,适用于成就视图控制器。任何其他 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];
    }
    

    【讨论】:

      【解决方案3】:

      尝试调用

           self.modalPresentationStyle = UIModalPresentationCurrentContext;
      

      在呈现 ViewController 之前

      【讨论】:

        猜你喜欢
        • 2014-08-26
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-10-05
        • 1970-01-01
        • 2014-03-26
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多