关于COCOS2D加入Game center屏幕翻转的问题

问题描述:COCOS2D开发中,加入Game Center的时候,会出现屏幕翻转时,Game Center的界面没有翻转的问题,在网上查找了好多资料,包括cocos2d-iphone的官网,貌似没找到比较合适的解决方法,或者是说我没看懂别人的方法。

 

在翻转屏幕的时候,是不会有什么问题,就是初始化的时候,不然屏幕转,gc的屏幕还是会转,比如:你初始化方向为UIInterfaceOrientationPortrait,但是当你屏幕为UIInterfaceOrientationLandscapeLeft || UIInterfaceOrientationLandscapeRight的时候,GC的屏幕还是不会固定UIInterfaceOrientationPortrait这个方向,还是会随着方向变化而变化,而且键盘会盖住邀请好友的按钮而无法邀请好友,为这个问题,懊恼了好几天,也找了好几天的解决方法。

 

也许是自己写法有问题,所以解决起来就比较麻烦。

就比如成就(Achievement),我就直接继承了CCLayer

.h文件

 //iPhone UI @interface QUUAchievement: GKAchievementViewController @end //iPad UI @interface QUUAchievementiPad : UIViewController { } @end @interface Achievement : CCLayer <GKAchievementViewControllerDelegate> { UIViewController* lbController; } - (void) showAchievements; - (void)achievementViewControllerDidFinish:(GKAchievementViewController *)viewController; @end @end

 

在.m文件里

 if(IsIphone) { lbController=[[UIViewController alloc] init]; } else { lbController=[[QUUAchievementiPad alloc] init]; } [[[CCDirector sharedDirector] openGLView] addSubview:lbController.view]; GameCenter* gCenter = [GameCenter shareInstance]; [gCenter authenticateLocalUser]; [self showAchievements]; - (void) showAchievements { GKAchievementViewController *achievements=nil; if(!IsIphone) achievements= [[GKAchievementViewController alloc] init]; else achievements=[[QUUAchievement alloc] init]; if (achievements != nil) { achievements.achievementDelegate = self; [lbController presentModalViewController: achievements animated: YES]; } [achievements release]; } - (void)achievementViewControllerDidFinish:(GKAchievementViewController *)viewController { [lbController dismissModalViewControllerAnimated:YES]; [lbController.view removeFromSuperview]; [lbController release]; // [[CCDirector sharedDirector] popScene]; } @implementation QUUAchievement -(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation { return NO; } @end @implementation QUUAchievementiPad -(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation { return (toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft || toInterfaceOrientation == UIInterfaceOrientationLandscapeRight); } @end

你可能感兴趣的:(UI,interface)