Custom animation when hiding UINavigationBar

I am making an application that shows / hides (in a custom animation) a UINavigationBar with one click.

I created two functions (one for showing and one for hiding). The UINavigationBar display function works fine:

- (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];
}

But the hide function, even if it is the same, does not work. UINavigationBar suddenly disappears without 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];
}

Call:

- (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];
    }
}

Does anyone know why this is happening?

+3
source share
1 answer

This happens because you call [self.navigationController setNavigationBarHidden:YES animated:NO];in the animation code, but the boolian values ​​are not animated. There is no "between values" value for bool values.

[self.navigationController setNavigationBarHidden:YES animated:NO]; ,

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

All Articles