我遇到的问题似乎是一个相当常见的问题,但我的解决方案的搜索和实现尚未成功。
我构建了一个 Cocos2d 游戏,该游戏仅供横向使用,但需要访问 Gamecenter。 Gamecenter 正在运行,启用了纵向模式,但它也允许游戏切换到纵向模式。
我已尝试以下修复:
游戏中心登录锁定横向仅在 iOS 6 中
仅横向应用程序中的 GameCenter 身份验证抛出 UIApplicationInvalidInterfaceOrientation
将 GameCenter 添加到仅限横向的 cocos2d 应用程序后,iOS 6 中出现错误
Cocos 2d 2.0 应该自动旋转不起作用?
我相信问题是我使用 CCLayers 而不是 UIViewControllers 构建了游戏
例子:
菜单层.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 不调用 usesupportedInterfaceOrientations 或 shouldAutorotate 是否正确?
或者我应该以某种方式更改此代码来解决问题:
// Create a Navigation Controller with the Director
navController_ = [[UINavigationController alloc] initWithRootViewController:director_];
navController_.navigationBarHidden = YES;