0

我使用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 - 它只是一個黑客...

回答

1

對於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 
+0

謝謝你的答案,但這個方向的修復不適合GKAchievementViewController工作爲了我。這個視圖在發射和解散之後仍然從底部向上滑動 - 進入屏幕的右側。 – 2012-02-06 12:29:00

+0

提醒一下,此代碼適用於GKMatchmakerViewController。你確定你修改它爲GKAchievementViewController嗎? – erkanyildiz 2012-02-20 23:08:21

+0

是的,當然..現在讓它以這種方式工作。稍後將進行調查。 – 2012-03-12 18:56:34

1

這是我第一次回答#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]; 
} 
0

嘗試調用

 self.modalPresentationStyle = UIModalPresentationCurrentContext; 

呈現的ViewController之前