Outre le sous-classement de votre tabBarController que vous avez primordial houldAutorotateToInterfaceOrientation, vous devez faire ce qui suit:
Dans la méthode viewDidLoad du contrôleur dans lequel vous souhaitez ajouter une vue à être mis en rotation:
self.view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
ajouter cette méthode déléguée dans le contrôleur dans lequel vous souhaitez ajouter une vue à tourner:
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
{
//NSLog(@"didRotateFromInterfaceOrientation");
if((fromInterfaceOrientation == UIInterfaceOrientationPortrait) ||
(fromInterfaceOrientation == UIInterfaceOrientationPortraitUpsideDown))
{
YourAppDelegate *mainDelegate = (YourAppDelegate *)[[UIApplication sharedApplication] delegate];
[mainDelegate.tabBarController.view addSubview: viewToBeRotated];
[viewToBeRotated setHidden:NO];
return;
}
if(fromInterfaceOrientation == UIInterfaceOrientationLandscapeLeft || fromInterfaceOrientation == UIInterfaceOrientationLandscapeRight)
{
[viewToBeRotated removeFromSuperview];
[self.view setHidden:NO];
}
}
Vous pouvez également ajouter la méthode suivante:
- (void)willAnimateFirstHalfOfRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
duration:(NSTimeInterval)duration {
if (toInterfaceOrientation == UIInterfaceOrientationPortrait)
{
//self.view = self.portrait;
YourAppDelegate *mainDelegate = (YourAppDelegate *)[[UIApplication sharedApplication] delegate];
[viewToBeRotated removeFromSuperview];
mainDelegate.tabBarController.view.transform = CGAffineTransformIdentity;
mainDelegate.tabBarController.view.transform = CGAffineTransformMakeRotation(degreesToRadian(0));
mainDelegate.tabBarController.view.bounds = CGRectMake(0.0, 0.0, 300.0, 480.0);
}
else if (toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft)
{
YourAppDelegate *mainDelegate = (YourAppDelegate *)[[UIApplication sharedApplication] delegate];
[mainDelegate.tabBarController.view addSubview: viewToBeRotated];
mainDelegate.tabBarController.view.transform = CGAffineTransformIdentity;
mainDelegate.tabBarController.view.transform = CGAffineTransformMakeRotation(degreesToRadian(-90));
mainDelegate.tabBarController.view.bounds = CGRectMake(0.0, 0.0, 460.0, 320.0);
}
else if (toInterfaceOrientation == UIInterfaceOrientationPortraitUpsideDown)
{
//self.view = self.portrait;
YourAppDelegate *mainDelegate = (YourAppDelegate *)[[UIApplication sharedApplication] delegate];
[viewToBeRotated removeFromSuperview];
mainDelegate.tabBarController.view.transform = CGAffineTransformIdentity;
mainDelegate.tabBarController.view.transform = CGAffineTransformMakeRotation(degreesToRadian(180));
mainDelegate.tabBarController.view.bounds = CGRectMake(0.0, 0.0, 300.0, 480.0);
}
else if (toInterfaceOrientation == UIInterfaceOrientationLandscapeRight)
{
YourAppDelegate *mainDelegate = (YourAppDelegate *)[[UIApplication sharedApplication] delegate];
[mainDelegate.tabBarController.view addSubview: viewToBeRotated];
mainDelegate.tabBarController.view.transform = CGAffineTransformIdentity;
mainDelegate.tabBarController.view.transform = CGAffineTransformMakeRotation(degreesToRadian(90));
mainDelegate.tabBarController.view.bounds = CGRectMake(0.0, 0.0, 460.0, 320.0);
}
}
Vous pouvez également jeter un oeil à
Rotating the iPhone, and instantiating a new UIViewController
TabBarController and navigationControllers in landscape mode
Je suis en fait échangeant deux points de vue. J'ai essayé de régler l'autoResizingMask, mais cela ne fonctionne toujours pas. Les deux autres méthodes que vous suggérez devraient être prises en compte par la méthode my - willAnimateFirstHalfOfRotationToInterfaceOrientation. Il bascule self.view en fonction de l'orientation. Cette méthode n'est jamais appelée. – Rob