简体   繁体   中英

Displaying Game Center modal view in landscape

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...

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

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

Try to call

     self.modalPresentationStyle = UIModalPresentationCurrentContext;

Before presenting the ViewController

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM