2012-05-23 2 views
3

Je crée une application qui affiche/cache (dans une animation personnalisée) le UINavigationBar en un seul clic.Animation personnalisée lors de la dissimulation de UINavigationBar

J'ai créé deux fonctions (une pour montrer et l'autre pour se cacher). La fonction pour montrer la UINavigationBar fonctionne parfaitement:

- (void) showNavigationBar { 
    [UINavigationBar beginAnimations:@"NavBarFadeIn" context:nil]; 
    self.navigationController.navigationBar.alpha = 0; 
    [UINavigationBar setAnimationCurve:UIViewAnimationCurveEaseIn]; 
    [UINavigationBar setAnimationDuration:0.5]; 
    [UINavigationBar setAnimationTransition:UIViewAnimationOptionTransitionFlipFromTop 
            forView:self.navigationController.navigationBar 
             cache:YES]; 
    self.navigationController.navigationBar.alpha = 1; 
    [UINavigationBar commitAnimations]; 
} 

Mais la fonction pour cacher, même si elle est la même chose, ne fonctionne pas. Le UINavigationBar disparaît soudainement sans animation.

- (void) hideNavigationBar { 
    [UINavigationBar beginAnimations:@"NavBarFadeOut" context:nil]; 
    self.navigationController.navigationBar.alpha = 1; 
    [UINavigationBar setAnimationCurve:UIViewAnimationCurveEaseIn]; 
    [UINavigationBar setAnimationDuration:0.5]; 
    [UINavigationBar setAnimationTransition:UIViewAnimationOptionTransitionCurlUp 
            forView:self.navigationController.navigationBar 
             cache:YES]; 
    self.navigationController.navigationBar.alpha = 0; 
    [self.navigationController setNavigationBarHidden:YES animated:NO]; 
    [UINavigationBar commitAnimations]; 
} 

L'appel:

- (void)contentView:(ReaderContentView *)contentView touchesBegan:(NSSet *)touches 
{ 
    if([[self navigationController] isNavigationBarHidden] == NO) 
    { 
    if (touches.count == 1) // Single touches only 
    { 
      UITouch *touch = [touches anyObject]; // Touch info 
      CGPoint point = [touch locationInView:self.view]; // Touch location 
      CGRect areaRect = CGRectInset(self.view.bounds, TAP_AREA_SIZE, TAP_AREA_SIZE); 

      if (CGRectContainsPoint(areaRect, point) == false) return; 
     } 
     [mainToolbar hideToolbar]; 
     [mainPagebar hidePagebar]; // Hide 

     [self hideNavigationBar]; 
     lastHideTime = [NSDate new]; 
    } 
} 

Tout le monde a la moindre idée de pourquoi cela se passe?

+0

Pouvez-vous envoyer le code où vous appelez -showNavigationBar et hideNavigationBar –

+0

je viens édité et inclus le code d'appel – crisisGriega

Répondre

3

Cela se produit, car vous appelez [self.navigationController setNavigationBarHidden:YES animated:NO]; dans le code d'animation, mais les valeurs booléennes ne sont pas animables. Il n'y a pas de "entre les valeurs" pour les valeurs bool.

Vous devez appeler [self.navigationController setNavigationBarHidden:YES animated:NO]; dans une méthode que vous planifiez après l'animation avec

[UINavigationBar setAnimationDidStopSelector: @selector(myCoolMethod:)]; 
+0

Merci beaucoup, je cherchais quelque chose comme ça. – crisisGriega

+0

qui m'aide aussi. Merci beaucoup. – FisherMartyn

Questions connexes