Changer Voir sur un seul onglet dans Tabbar-Application (Paysage-Portrait)?
-
19-09-2019 - |
Question
Comment puis-je changer la vue lors de la rotation de l'iPhone (nib de changement de). Mais il faut se produit que dans un seul onglet! Je l'ai essayé avec:
- (void)viewDidLoad {
LandscapeViewController *viewController = [[LandscapeViewController alloc]
initWithNibName:@"LandscapeView" bundle:nil];
self.landscapeViewController = viewController;
[viewController release];
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(orientationChanged:)
name:UIDeviceOrientationDidChangeNotification object:nil]; }
- (void)orientationChanged:(NSNotification *)notification
{
[self performSelector:@selector(updateLandscapeView) withObject:nil afterDelay:0];
}
- (void)updateLandscapeView
{
UIDeviceOrientation deviceOrientation = [UIDevice currentDevice].orientation;
if (UIDeviceOrientationIsLandscape(deviceOrientation) && !isShowingLandscapeView)
{
[self presentModalViewController:self.landscapeViewController animated:YES];
isShowingLandscapeView = YES;
}
else if (deviceOrientation == UIDeviceOrientationPortrait && isShowingLandscapeView)
{
[self dismissModalViewControllerAnimated:YES];
isShowingLandscapeView = NO;
}
}
Mais le paysage Voir apparaît dans tous les onglets. (Lorsque ce code est chargé une fois). Toute idée?
La solution 3
Tanks pour vos commentaires! J'ai trouvé une solution de contournement:
//Remove Observer if not in Landscape
- (void)viewDidDisappear:(BOOL)animated {
if (isShowingLandscapeView == NO) {
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIDeviceOrientationDidChangeNotification object:nil];
}
}
//Add Observer if not in Landscape
- (void)viewDidAppear:(BOOL)animated {
if (isShowingLandscapeView == NO) {
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(orientationChanged:) name:UIDeviceOrientationDidChangeNotification object:nil];
}
}
Autres conseils
Qu'est-ce qui se passe est votre contrôleur de vue reçoit la notification de UIDeviceOrientationDidChangeNotification
chaque fois que les changements de rotation, que ce soit ou non est affiché. essayer au lieu d'utiliser les méthodes de UIViewController
intégrées qui sont destinés à répondre à des rotations.
est de Docs d'Apple (View Controller Guide de programmation):
Contrôleurs de barre d'onglets et Rotation de la vue
contrôleurs de barre d'onglets supportent un portrait l'orientation par défaut et ne pas tourner à une orientation paysage à moins que toute la vue racine soutenir un tel contrôleurs orientation. Lorsqu'une orientation de l'appareil le changement se produit, la languette de commande de barre interroge sa gamme de contrôleurs de vue. Si l'un d'eux ne supporte pas l'orientation, la barre d'onglets contrôleur ne change pas orientation.
Alors, je ne suis pas sûr que le contrôleur de la barre d'onglets est conçu pour tourner juste pour une seule vue.