Modification des UIViews pendant l'interface UIInterfaceOrientation sur iPad

J'essaie de changer de sharepoint vue sur la rotation parce que mon sharepoint vue doit être sensiblement différent du portrait au paysage. Maintenant, le code que j'utilise fonctionne une fois, l'application se bloque en essayant de faire demi-tour. Les deux directions ne font pas de différence. Par exemple: Si je suis en mode Paysage et que je passe au mode portrait, tout fonctionne bien jusqu'à ce que je returnne en mode paysage, puis il se fige et ne fait absolument rien.

Voici le code que j'utilise pour réaliser ceci

Dans ma méthode "viewDidLoad"

[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didRotate:) name:UIDeviceOrientationDidChangeNotification object:nil]; 

Ensuite, je l'appelle pour la rotation:

 - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { // Return YES for supported orientations return YES; } - (void)didRotate:(NSNotification *)notification { UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation]; if ((orientation == UIDeviceOrientationLandscapeLeft) || (orientation == UIDeviceOrientationLandscapeLeft)) { // present the other viewController, it's only viewable in landscape [self.view addSubview:landScapeView]; } if ((orientation == UIDeviceOrientationLandscapeRight) || (orientation == UIDeviceOrientationLandscapeRight)) { // present the other viewController, it's only viewable in landscape [self.view addSubview:landScapeView]; } else if ((orientation == UIDeviceOrientationPortrait || (orientation == UIDeviceOrientationPortrait)) { // get rid of the landscape controller [self.view addSubview:portrait]; } else if ((orientation == UIDeviceOrientationPortraitUpsideDown || (orientation == UIDeviceOrientationPortraitUpsideDown)) { // get rid of the landscape controller [self.view addSubview:portrait]; } } 

Vous ajoutez votre vue spécifique d'orientation à la rotation mais jamais en supprimant l'autre dont vous avez besoin.

 // get rid of the landscape controller ((orientation == UIDeviceOrientationPortraitUpsideDown || orientation == UIDeviceOrientationPortraitUpsideDown)) { [landScapeView removeFromSuperview]; [self.view addSubview:portrait]; } 

Et similaire dans l'autre sens.

Gardez à l'esprit qu'en supprimant les versions de superview, vous devez conserver les deux vues de manière externe.