我有似乎是一個相當普遍的問題,但我的解決方案的搜索和實現尚未解決。Gamecenter身份驗證僅適用於iOS 6的Cocos2d與CCLayer 6
我已經構建了一個Cocos2d遊戲,目的只是爲了風景,但需要訪問Gamecenter。 Gamecenter正在開展工作,並啓用了肖像模式,但它也允許遊戲轉到肖像模式。
我已經嘗試以下修正:
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?
我相信這個問題是我建立的使用CCLayers遊戲而不是UIViewControllers
例子: 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.
}
}];
}
}
}
...
因爲我已經建立了使用CCLayers代替UIViewControllers的比賽中,我有什麼辦法?我是否正確地認爲CCLayers不會調用supportedInterfaceOrientations或shouldAutorotate?
或者我應該以某種方式改變這個代碼來解決這個問題:
// Create a Navigation Controller with the Director
navController_ = [[UINavigationController alloc] initWithRootViewController:director_];
navController_.navigationBarHidden = YES;
如果您的問題是關於Game Center登錄屏幕僅處於肖像模式,那麼您就必須忍受這種情況。登錄發生在肖像。我沒有聽說過,也沒有看到有人爲此做過工作。 – LearnCocos2D