ios ipad: rotation de TabBar sur le côté gauche en mode paysage, avec mise à jour de la transformation et de la contrainte

Je crée une application ios IPad qui a un contrôle UITabBar positionné en bas avec 3 MenuItems dedans. Normalement, lorsque je fais pivoter l'appareil, la tabulation rest en bas dans le paysage. Je voudrais que le TabBar tourne sur le côté gauche en mode Paysage et devienne une représentation verticale. Je ne veux pas créer un UIView avec des buttons si possible, parce que j'aimerais que le même object gère les deux, et j'aime la commodité du TabBar normal.

Mon plan consistait à détecter la position du périphérique et à utiliser un UITransform pour faire pivoter le TabBar de 90 degrés en mode paysage. Ignorons l'icône et la rotation du text à l'intérieur pour l'instant, et concentrons-nous sur le TabBar global lui-même.

La rotation fonctionne, sauf qu'elle laisse le TabBar vertical en bas au centre de l'écran. La tâche suivante consistait à le contraindre au mur de gauche. Normalement j'utilise 3 contraintes pour maintenir le TabBar sur les côtés gauche / bas / droit. J'ai beaucoup de mal à find les bonnes contraintes pour le garder correctement sur le côté gauche.

Un problème principal est qu'une fois la transformation terminée, les attributes height et width sont inversés (ou également transformés) dans la barre d'tabs. Tellement élevé le rend plus large sur l'écran, et la largeur le rend plus grand. L'utilisation de contraintes haut / bas avec une hauteur de 49 est ce qui est apparemment requirejs, sauf que le combo haut / bas + hauteur provoque un conflit de contraintes.

J'attache ma logique de contrainte actuelle qui fonctionne raisonnablement, mais je n'arrive pas à comprendre pourquoi j'ai besoin de coder en dur ces valeurs comme indiqué. C'était le seul moyen d'get la sortie visuelle sur le côté gauche. Je me request s'il existe une façon plus propre de faire cela, peut-être sans valeurs codées en dur pour les constantes.

Je ne suis pas sûr non plus comment je finirai par faire tourner le text + icons comme prochaine étape.

Ci-joint également comment il apparaît actuellement. Il est vert pour illustrer clairement mais sera finalement transparent, de sorte que la coupure au sumt du paysage ne sera pas un problème.

- (void) adjustViewsForOrientation:(UIInterfaceOrientation) orientation { switch (orientation) { case UIInterfaceOrientationPortrait: case UIInterfaceOrientationPortraitUpsideDown: { //load the portrait view // revert to normal transform _tabBar.transform = CGAffineTransformRotate(CGAffineTransformIdentity, M_PI*2); [self.view removeConstraint:_tabbarConstraintT]; [self.view removeConstraint:_tabbarConstraintR]; [self.view removeConstraint:_tabbarConstraintB]; [self.view removeConstraint:_tabbarConstraintL]; // right space _tabbarConstraintR = [NSLayoutConstraint constraintWithItem:_tabBar atsortingbute:NSLayoutAtsortingbuteTrailing relatedBy:NSLayoutRelationEqual toItem:self.view atsortingbute:NSLayoutAtsortingbuteTrailing multiplier:1.0 constant:0.0]; // bottom space _tabbarConstraintB = [NSLayoutConstraint constraintWithItem:_tabBar atsortingbute:NSLayoutAtsortingbuteBottom relatedBy:NSLayoutRelationEqual toItem:self.view atsortingbute:NSLayoutAtsortingbuteBottom multiplier:1.0 constant:0.0]; // left space _tabbarConstraintL = [NSLayoutConstraint constraintWithItem:_tabBar atsortingbute:NSLayoutAtsortingbuteLeading relatedBy:NSLayoutRelationEqual toItem:self.view atsortingbute:NSLayoutAtsortingbuteLeading multiplier:1.0 constant:0.0]; //[self.view addConstraint:_tabbarConstraintT]; [self.view addConstraint:_tabbarConstraintR]; [self.view addConstraint:_tabbarConstraintB]; [self.view addConstraint:_tabbarConstraintL]; } break; case UIInterfaceOrientationLandscapeLeft: case UIInterfaceOrientationLandscapeRight: { //load the landscape view _tabBar.transform = CGAffineTransformRotate(CGAffineTransformIdentity, M_PI/2); [self.view removeConstraint:_tabbarConstraintT]; [self.view removeConstraint:_tabbarConstraintR]; [self.view removeConstraint:_tabbarConstraintB]; [self.view removeConstraint:_tabbarConstraintL]; NSLog(@"frame: %f,%f",_tabBar.frame.size.height,_tabBar.frame.size.width); // top space _tabbarConstraintT = [NSLayoutConstraint constraintWithItem:_tabBar atsortingbute:NSLayoutAtsortingbuteTop relatedBy:NSLayoutRelationEqual toItem:self.view atsortingbute:NSLayoutAtsortingbuteTop multiplier:1.0 constant:[UIScreen mainScreen].bounds.size.height/2+49]; // left space _tabbarConstraintL = [NSLayoutConstraint constraintWithItem:_tabBar atsortingbute:NSLayoutAtsortingbuteLeading relatedBy:NSLayoutRelationEqual toItem:self.view atsortingbute:NSLayoutAtsortingbuteLeading multiplier:1.0 constant:-360.0]; // effective width _tabbarConstraintR = [NSLayoutConstraint constraintWithItem:_tabBar atsortingbute:NSLayoutAtsortingbuteHeight relatedBy:NSLayoutRelationEqual toItem: nil atsortingbute:NSLayoutAtsortingbuteHeight multiplier:1.0f constant:49]; // effective height _tabbarConstraintB = [NSLayoutConstraint constraintWithItem:_tabBar atsortingbute:NSLayoutAtsortingbuteWidth relatedBy:NSLayoutRelationEqual toItem: nil atsortingbute:NSLayoutAtsortingbuteWidth multiplier:1.0f constant:[UIScreen mainScreen].bounds.size.height]; [self.view addConstraint:_tabbarConstraintR]; [self.view addConstraint:_tabbarConstraintB]; [self.view addConstraint:_tabbarConstraintT]; [self.view addConstraint:_tabbarConstraintL]; } break; case UIInterfaceOrientationUnknown:break; } } 

entrez la description de l'image icientrez la description de l'image ici