Custom animation when hiding UINavigationBar

為{幸葍}努か 提交于 2020-01-01 15:07:41

问题


I'm making an application which shows/hides (in custom animation) the UINavigationBar on single tap.

I have created two functions (one for showing and the other for hiding). The function for showing the UINavigationBar works perfectly:

- (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 function for hiding it, even if it's the same, doesn't work. The UINavigationBar disappears suddenly with no 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];
}

The calling:

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

Anybody has a clue about why this is happening?


回答1:


It is happening, because you are calling [self.navigationController setNavigationBarHidden:YES animated:NO]; in the animation code but boolian values are not animatable. There is no "in between values" for bool values.

You should call [self.navigationController setNavigationBarHidden:YES animated:NO]; in a method which you schedule after the animation with

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


来源:https://stackoverflow.com/questions/10718539/custom-animation-when-hiding-uinavigationbar

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!