Animation personnalisée lors de la dissimulation de UINavigationBar

Je fais une application qui montre / cache (en animation personnalisée) le UINavigationBar en un seul clic.

J'ai créé deux fonctions (une pour montrer et l'autre pour cacher). La fonction pour afficher le 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 le cacher, même si c'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]; } } 

Quelqu'un a la moindre idée de la raison pour laquelle cela se produit?

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

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

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