Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9113425
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T03:57:42+00:00 2026-06-17T03:57:42+00:00

I’m having what seems to be a fairly common problem, but my searches and

  • 0

I’m having what seems to be a fairly common problem, but my searches and implementations of solutions have not worked out.

I’ve built a Cocos2d game that is intended to be landscape only, but needs to access Gamecenter. Gamecenter is working, with portrait mode enabled, but it’s also allowing the game to flip to portrait mode too.

I’ve attempted the following fixes:

Game center login lock in landscape only in i OS 6

GameCenter authentication in landscape-only app throws UIApplicationInvalidInterfaceOrientation

Error in iOS 6 after adding GameCenter to a landscape-only cocos2d app

Cocos 2d 2.0 shouldAutorotate not working?

I believe the problem is that I’ve built the game using CCLayers instead of UIViewControllers

Example:
MenuLayer.h

@interface MenuLayer : CCLayer <GKAchievementViewControllerDelegate, GKLeaderboardViewControllerDelegate, UINavigationControllerDelegate>{
   ..my header info..
}

MenuLayer.m

...
-(NSUInteger)supportedInterfaceOrientations {
    return UIInterfaceOrientationMaskLandscape;
}
-(BOOL)shouldAutorotate {
    return [[UIDevice currentDevice] orientation] != UIInterfaceOrientationPortrait;
}

-(void)authenticateLocalPlayer
{

    GKLocalPlayer * localPlayer= [GKLocalPlayer localPlayer];

    if(localPlayer.authenticated == NO)
    {
        NSString *reqSysVer = @"6.0";
        NSString *currSysVer = [[UIDevice currentDevice] systemVersion];
        if ([currSysVer compare:reqSysVer options:NSNumericSearch] != NSOrderedAscending)
        {
            [[GKLocalPlayer localPlayer] setAuthenticateHandler:(^(UIViewController* viewcontroller, NSError *error) {
                if (viewcontroller != nil) {
                    AppController *app = (AppController*) [[UIApplication sharedApplication] delegate];
                    [[app navController] presentModalViewController:viewcontroller animated:YES];
                }else if ([GKLocalPlayer localPlayer].authenticated)
                {
                    //do some stuff
                }
            })];
        }
        else
        {
            [localPlayer authenticateWithCompletionHandler:^(NSError *error){
                if(localPlayer.isAuthenticated)
                {
                    //Peform Additionl Tasks for the authenticated player.
                }
            }];
        }
    }

}
...

Since I’ve built the game using CCLayers instead of UIViewControllers, what alternatives do I have? Am I correct in assuming that CCLayers don’t call use supportedInterfaceOrientations or shouldAutorotate?

Or am I supposed be changing this code somehow to fix the problem:

// Create a Navigation Controller with the Director
navController_ = [[UINavigationController alloc] initWithRootViewController:director_];
navController_.navigationBarHidden = YES;
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T03:57:43+00:00Added an answer on June 17, 2026 at 3:57 am

    This frustrated me for awhile too. After digging around for awhile on the ‘Net I found a couple of sources and some worked with iOS 6, some with iOS5, but I had to make some modifications so that it worked the way I wanted on both iOS5 and iOS6. This is the code I am using, it works on my iPhone using 5.1 and 6. Note that the Game Center login still comes up in portrait orientation, there doesn’t appear to be anything you can do about that. But the rest of the game will remain in landscape mode.

    1. enable portrait mode as a supported orientation in your build settings (info.plist).
    2. Create a new subclass of UINavigationController. Name this class whatever makes sense to you.
    3. In your AppDelegate, include your new custom UINavigationController header file.
    4. In your App Delegate, comment out the original call and instead call your custom class.

    That should do the trick. Here is the code from my custom class:

    #import <UIKit/UIKit.h>
    
    @interface CustomNavigationViewController : UINavigationController
    
    -(UIInterfaceOrientation) getCurrentOrientation;
    
    @end
    

    And the implementation file:

    #import "CustomNavigationViewController.h"
    
    @interface CustomNavigationViewController ()
    
    @end
    
    @implementation CustomNavigationViewController
    
    - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
    {
        self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
        if (self) {
            // Custom initialization
        }
        return self;
    }
    
    - (void)viewDidLoad
    {
        [super viewDidLoad];
        // Do any additional setup after loading the view.
    }
    
    - (void)didReceiveMemoryWarning
    {
        [super didReceiveMemoryWarning];
        // Dispose of any resources that can be recreated.
    }
    
    // This is required to allow GameCenter to login in portrait mode, but only allow landscape mode for the rest of the game play/
    // Arrrgg!
    
    -(BOOL) shouldAutorotate {
        return YES;
    }
    
    -(NSUInteger) supportedInterfaceOrientations {
        return UIInterfaceOrientationMaskLandscape;
    }
    
    -(UIInterfaceOrientation) preferredInterfaceOrientationForPresentation {
        return UIInterfaceOrientationLandscapeRight; // or left if you prefer
    }
    
    -(NSUInteger) application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window {
        if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
            return UIInterfaceOrientationMaskLandscape;
        else {
            return UIInterfaceOrientationMaskAllButUpsideDown;
        }
    }
    
    -(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
        return [[UIDevice currentDevice] orientation] != UIInterfaceOrientationPortrait;
    }
    
    -(UIInterfaceOrientation) getCurrentOrientation {
        return [[UIDevice currentDevice] orientation];
    }
    
    @end
    

    Note that last method getCurrentOrientation isn’t required I just put that in there in case I wanted to determine what the current orientation is.

    The custom class is called in AppDelegate.m like this: (comment out the original code)

    navController = [[CustomNavigationViewController alloc] initWithRootViewController:director];
    window.rootViewController = navController;
    navController.navigationBarHidden = YES;
    [window makeKeyAndVisible];
    

    Hope this helps.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a French site that I want to parse, but am running into
This could be a duplicate question, but I have no idea what search terms
I have been unable to fix a problem with Java Unicode and encoding. The
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
this is what i have right now Drawing an RSS feed into the php,
I have a small JavaScript validation script that validates inputs based on Regex. I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.