Dans les exemples Apples vous averti via la méthode déléguée:
- (void)orientationChanged:(NSNotification *)notification
{
// We must add a delay here, otherwise we'll swap in the new view
// too quickly and we'll get an animation glitch
NSLog(@"orientationChanged");
[self performSelector:@selector(updateLandscapeView) withObject:nil afterDelay:0];
}
Et puis pour afficher un écran de portrait:
- (void)updateLandscapeView
{
PortraitView *portraitView = [[PortraitView alloc] init];
portraitView.delegate = self;
UIDeviceOrientation deviceOrientation = [UIDevice currentDevice].orientation;
if (UIDeviceOrientationIsLandscape(deviceOrientation) && !isShowingLandscapeView)
{
[self presentModalViewController: portraitView animated:YES];
isShowingLandscapeView = YES;
}
else if (deviceOrientation == UIDeviceOrientationPortrait && isShowingLandscapeView)
{
[self dismissModalViewControllerAnimated:YES];
isShowingLandscapeView = NO;
}
[portraitView release];
}
Bien sûr, vous devez concevoir la PortraitView en tant que classe de délégué pour que cela fonctionne comme prévu.
Pas le seul moyen, mais je trouve que cela fonctionne bien et ses exemples dans les pommes. Je ne le ferais pas dans l'Appdelegate, mais plutôt votre opinion, je ne sais pas votre conception si.
s'il vous plaît voir ma nouvelle réponse Je vais vous expliquer un nouveau problème que j'ai avec votre solution – ludo