隐藏UINavigationBar时的自定义动画 [英] Custom animation when hiding UINavigationBar

查看:76
本文介绍了隐藏UINavigationBar时的自定义动画的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在制作一个可通过单击显示/隐藏(以自定义动画的形式)UINavigationBar的应用程序.

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

我创建了两个函数(一个用于显示,另一个用于隐藏).用于显示UINavigationBar的功能可以正常工作:

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

但是,即使它是相同的,用于隐藏它的功能也不起作用.UINavigationBar突然消失,没有动画.

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

呼叫:

- (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?

推荐答案

正在发生,因为您在动画代码中调用了 [self.navigationController setNavigationBarHidden:YES animation:NO]; ,但布尔值值不可动画.布尔值没有介于两个值之间".

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.

您应使用在

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

这篇关于隐藏UINavigationBar时的自定义动画的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆