我遇到了一个似乎相当普遍的问题,但我对解决方案的搜索和实施并没有成功。
我已经构建了一个 Cocos2d 游戏,该游戏仅用于横向,但需要访问 Gamecenter。Gamecenter 正在运行,启用了纵向模式,但它也允许游戏切换到纵向模式。
我尝试了以下修复:
仅横向应用程序中的 GameCenter 身份验证引发 UIApplicationInvalidInterfaceOrientation
将 GameCenter 添加到仅限横向的 cocos2d 应用程序后,iOS 6 出现错误
Cocos 2d 2.0 shouldAutorotate 不工作?
我相信问题在于我使用 CCLayers 而不是 UIViewControllers 构建了游戏
示例:MenuLayer.h
@interface MenuLayer : CCLayer <GKAchievementViewControllerDelegate, GKLeaderboardViewControllerDelegate, UINavigationControllerDelegate>{
..my header info..
}
菜单层.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.
}
}];
}
}
}
...
由于我使用 CCLayers 而不是 UIViewControllers 构建了游戏,我有什么替代方案?我假设 CCLayers 不调用 use supportedInterfaceOrientations 或 shouldAutorotate 是否正确?
或者我应该以某种方式更改此代码以解决问题:
// Create a Navigation Controller with the Director
navController_ = [[UINavigationController alloc] initWithRootViewController:director_];
navController_.navigationBarHidden = YES;