如何禁用navigationBar动画? [英] How to disable navigationBar animation?

查看:121
本文介绍了如何禁用navigationBar动画?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个UITableViewController,当我点击下一个第一个UITableViewController,第二个UITableViewController得到推送在导航堆栈和动画的过渡像正常。我想让它,所以当我推下一个,只有视图的动画,和导航栏不(保持不变)。我已经非常接近这样做的代码如下:

I have two UITableViewControllers such that when I click next on the first UITableViewController, the second UITableViewController gets pushed on the navigation stack and animates the transition like normal. I'd like to make it so when I push next, only the views animate, and the navigation bar doesn't (stays the same). I've gotten very close to doing this with the code below:

- (void) viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];

    CATransition *navTransition = [CATransition animation];
    navTransition.duration = .5;
    navTransition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
    navTransition.type = kCATransitionPush;
    navTransition.subtype = kCATransitionPush;
    [self.navigationController.navigationBar.layer addAnimation:navTransition forKey:nil];

}

我把这个代码,我也让它两个导航栏上的标题和按钮在每个UITableViewController中完全相同。它几乎工作,问题是,当动画发生时导航栏闪烁。有没有反正要让它不闪烁,或有任何其他好的方法来防止导航栏的动画发生(即禁用动画的图层或某物)?

I put this code, and I also make it so the title and buttons on both navigation bars are exactly same in each UITableViewController. It almost works, problem is, the navigation bar blinks when the animation occurs. Is there anyway to get it to not blink, or is there any other good way to prevent the animation of the navbar from occurring (ie disabling the animation on the layer or something)?

更新:任何人有任何其他想法?仍然在努力。

UPDATE: Anyone got any other ideas? Still struggling with this.

推荐答案

这是我想出的。下面是第一个viewController的顺序:

This is what I came up with. Here is the code for the first viewController in the sequence:

- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated
{
        if (viewController == self)
        {
                if (self.isInitialized)
                {
                        CATransition *navigationBarAnimation = [CATransition animation];
                        navigationBarAnimation.duration = 1.5;
                        navigationBarAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn];;
                        navigationBarAnimation.type = kCATransitionFade;
                        navigationBarAnimation.subtype = kCATransitionFade;
                        navigationBarAnimation.removedOnCompletion = YES;
                        [self.navigationController.navigationBar.layer addAnimation:navigationBarAnimation forKey:nil];
                }
                else 
                {
                        self.isInitialized = YES;
                }
        }
}

- (void)navigationController:(UINavigationController *)navigationController didShowViewController:(UIViewController *)viewController animated:(BOOL)animated
{
        if (viewController == self)
        {
                if (self.isInitialized)
                {
                        [self.navigationController.navigationBar.layer removeAllAnimations];
                }
        }
}

第二个视图控制器:

- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated
{
        if (viewController == self)
        {
                if (!self.isInitialized)
                {
                        CATransition *navigationBarAnimation = [CATransition animation];
                        navigationBarAnimation.duration = 1.5;
                        navigationBarAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn];;
                        navigationBarAnimation.type = kCATransitionFade;
                        navigationBarAnimation.subtype = kCATransitionFade;
                        navigationBarAnimation.removedOnCompletion = YES;
                        [self.navigationController.navigationBar.layer addAnimation:navigationBarAnimation forKey:nil];
                        self.isInitialized = YES;
                }
        }
}

- (void)navigationController:(UINavigationController *)navigationController didShowViewController:(UIViewController *)viewController animated:(BOOL)animated
{
        if (viewController == self)
        {
                if (self.isInitialized)
                {
                        [self.navigationController.navigationBar.layer removeAllAnimations];
                }
        }
}

您必须使用 UINavigationController 委托方法来确定是否显示 UIViewController 。然后对于每个 UIViewController ,需要使 BOOL isInitialized 属性,所以它帮助你确定什么时候 UIViewController 被推栈,或当它被显示,因为你推回到下一个 UIViewController

You have to use the UINavigationController delegate methods to figure out when the UIViewController is being shown. Then for each UIViewController, need to make a BOOL isInitialized property so it helps you determine when the UIViewController is being pushed on the stack, or when it's being shown because you pushed back on the next UIViewController.

这篇关于如何禁用navigationBar动画?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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