在风景中显示游戏中心模式视图
问题描述:
我使用cocos2d引擎,但没有自动旋转,只使用横向方向。在风景中显示游戏中心模式视图
我想显示标准的GC成就模态视图。 通常从屏幕底部(将设备保持在横向)显示,但屏幕右侧(如纵向模式视图)不显示。这似乎正在改变解雇动画的方向,但在此之前,观点并不旋转。它只是向右滑动。
而且我在控制台收到了警告:
Unbalanced calls to begin/end appearance transitions for <UIViewController: 0x41b9a0>.
这就是我如何显示此控制器:
-(void)showAchievements:(id) sender {
utilityController = [[UIViewController alloc] initWithNibName:nil bundle:nil];
[[[CCDirector sharedDirector] openGLView] addSubview:utilityController.view];
GKAchievementViewController *achievements = [[GKAchievementViewController alloc] init];
if (achievements != nil)
{
achievements.achievementDelegate = self;
[utilityController presentModalViewController: achievements animated: YES];
}
[achievements release];
}
- (void)achievementViewControllerDidFinish:(GKAchievementViewController *)viewController
{
[utilityController dismissModalViewControllerAnimated:YES];
[utilityController release];
}
在gameConfig.h我有以下配置:
#define GAME_AUTOROTATION kGameAutorotationNone
尝试将其更改为kGameAutorotationCCDirector
- 同样的事情。 kGameAutorotationUIViewController
- uiviews在整个屏幕上跳跃。
请不要建议与CGAffineTransformMakeRotation
旋转的UIView - 它只是一个黑客...
答
对于Kobold2D我解决了这个对于一个category for the GKMatchmakerViewController所有方向。您可以为其他Game Center视图控制器创建相同的类别。
这将迫使GC意见使用当前的设备方向:
@implementation GKMatchmakerViewController (OrientationFix)
-(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// [RootViewController option removed for clarity]
// all other autorotation types use the current device orientation
ccDeviceOrientation orientation = [CCDirector sharedDirector].deviceOrientation;
switch (interfaceOrientation)
{
case UIInterfaceOrientationPortrait:
return (orientation == kCCDeviceOrientationPortrait);
break;
case UIInterfaceOrientationPortraitUpsideDown:
return (orientation == kCCDeviceOrientationPortraitUpsideDown);
break;
case UIInterfaceOrientationLandscapeLeft:
return (orientation == kCCDeviceOrientationLandscapeRight);
break;
case UIInterfaceOrientationLandscapeRight:
return (orientation == kCCDeviceOrientationLandscapeLeft);
break;
default:
break;
}
return NO;
}
@end
答
这是我第一次回答#2,所以请原谅我,如果任何格式可能无法正常工作。
无论如何,代码。这个解决方案适用于我的Achievements-Viewcontroller。任何其他GK视图控制器可以相应工作...
@implementation GKAchievementViewController (OrientationFix)
-(BOOL) shouldAutorotateToInterfaceOrientation: (UIInterfaceOrientation)interfaceOrientation
{
return UIInterfaceOrientationIsLandscape(interfaceOrientation);
}
@end
@interface GKLeaderboardViewController (OrientationFix)
@end
-(void)showAchievements
{
GKAchievementViewController *achievements = [[GKAchievementViewController alloc] init];
if (achievements != nil)
{
achievements.achievementDelegate = self;
[self presentModalViewController: achievements animated: YES];
}
[achievements release];
}
- (void)achievementViewControllerDidFinish: (GKAchievementViewController *)viewController
{
AppDelegate *delegate = [UIApplication sharedApplication].delegate;
[delegate.viewController dismissModalViewControllerAnimated:YES];
}
答
尝试调用
self.modalPresentationStyle = UIModalPresentationCurrentContext;
呈现的ViewController之前
谢谢你的答案,但这个方向的修复不适合GKAchievementViewController工作为了我。这个视图在发射和解散之后仍然从底部向上滑动 - 进入屏幕的右侧。 – 2012-02-06 12:29:00
提醒一下,此代码适用于GKMatchmakerViewController。你确定你修改它为GKAchievementViewController吗? – erkanyildiz 2012-02-20 23:08:21
是的,当然..现在让它以这种方式工作。稍后将进行调查。 – 2012-03-12 18:56:34