2010-10-29 5 views
4

version Cocos2d: v0.99.04Game Center - orientation

J'ajoute Game Center à mon application actuelle et je l'ai trouvé un peu de code pour ouvrir le GKMatchmakerViewController. Il semble bien fonctionner, sauf quand il est rejeté, il change l'orientation du simulateur en portrait. Le jeu ne fonctionne que dans le paysage. Je ramène l'appareil en mode paysage et toutes les scènes cocos2d fonctionnent toujours correctement, mais si j'ouvre une alerte ou un sélecteur, elles s'ouvrent en mode portrait. Je peux ouvrir et fermer des scènes, mais elles vont maintenant toutes afficher ce comportement. Cela se produit en utilisant un périphérique réel également.

// *.h 
UIViewController *tempVC; 

// *.m 

// Open 

GKMatchRequest *request = [[[GKMatchRequest alloc] init] autorelease]; 
request.minPlayers = 2; 
request.maxPlayers = 2; 

GKMatchmakerViewController *mmvc = [[[GKMatchmakerViewController alloc] initWithMatchRequest:request] autorelease]; 
mmvc.matchmakerDelegate = self; 

tempVC=[[UIViewController alloc] init]; 
[[[CCDirector sharedDirector] openGLView] addSubview:tempVC.view]; 
[tempVC presentModalViewController: mmvc animated: YES];  

// Close 

[tempVC dismissModalViewControllerAnimated:YES]; 
[tempVC.view removeFromSuperview]; 
[tempVC release]; 

Dès que j'appuie sur le bouton dismissModalViewControllerAnimated, le simulateur tourne.

Merci d'avance pour toute aide.

Répondre

0

J'ai eu le même problème (ne pas utiliser cocos2d) et je résolus par le sous-classement UIViewController que le Game Center est fixé à:

@interface GameCenterViewController : UIViewController 
{ 
} 

-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation; 

@end 


@implementation GameCenterViewController 

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation 
{ 
    // Does it match my screenOrientation? 
     if (sceneOrientation == (UIDeviceOrientation)toInterfaceOrientation) 
     return YES; 

    return NO; 
} 

@end 
0

Mettre cela en AppDelegate.m avant @implementation

@interface UINavigationController (Private) 

- (NSUInteger)supportedInterfaceOrientations; 
- (BOOL)shouldAutorotate; 

@end 

@implementation UINavigationController (Private) 

- (NSUInteger)supportedInterfaceOrientations 
{ 
    return UIInterfaceOrientationMaskLandscape; 
} 

- (BOOL)shouldAutorotate 
{ 
    return YES; 
} 

@end 
Questions connexes