以横向方式显示 Game Center 模态视图

发布于 2025-01-02 04:44:24 字数 1342 浏览 0 评论 0原文

我正在仅横向使用 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 - uiview 在屏幕上跳跃。

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

I am using cocos2d engine in landscape-only orientation with no autorotation.

I want to display standart GC achievements modal view.
It's showing up normally, from bottom of screen (while holding device in landscape), but it is dismissing to the right side of the screen (like portrait modal views). It's seems to be changing orientation for dismiss animation, but view is not rotating before this. It's just sliding to the right.

Also I get a warning in console:

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

That's how I showing this controller:

-(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];
}

In gameConfig.h I have following configuration:

#define GAME_AUTOROTATION kGameAutorotationNone

Tried to change this to kGameAutorotationCCDirector - same thing. kGameAutorotationUIViewController - uiviews are jumping all over the screen.

Please do not suggest rotating UIView with CGAffineTransformMakeRotation - it's just a hack...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

陌上青苔 2025-01-09 04:44:24

对于 Kobold2D 我用 类别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

For Kobold2D I solved this for all orientations with a category for the GKMatchmakerViewController. You can make the same category for the other Game Center view controllers.

This will force the GC views to use the current device orientation:

@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
写下不归期 2025-01-09 04:44:24

这是我在 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];
}

This is my first ever answer on Stackoverflow, so please forgive me if any formatting may not work.

Anyway, on to the code. This solution works for me, for the Achievements-Viewcontroller. Any other GK-Viewcontroller may work accordingly...

@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];
}
盛夏已如深秋| 2025-01-09 04:44:24

尝试

     self.modalPresentationStyle = UIModalPresentationCurrentContext;

在呈现 ViewController 之前调用

Try to call

     self.modalPresentationStyle = UIModalPresentationCurrentContext;

Before presenting the ViewController

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文