NavBar每个控制器的颜色动画

NavBar每个控制器的颜色动画

本文介绍了iOS 7 UINavigationController NavBar每个控制器的颜色动画的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有任何方法可以有不同的 c> [UIView transitionWithView:...] 更改 barTintColor c $ c>阻塞与 UIViewAnimationOptionTransitionCrossDissolve ,但不是动画变化。

  • 我想在实施新的iOS 7自定义过渡计算和改变导航条的颜色,但是似乎是大的过度杀戮特别是如果我想保持原始动画出现无处不在)

    • viewWillAppear (view lifecycle) methods, but there is no way to animate the barTintColor (like setBarTintColor:animated:)
    • To change barTintColor in [UIView animation...] block, but that just weirdly animates frame of (probably) some background layer instead of smooth color transition.
    • To change barTintColor in [UIView transitionWithView:...] block with UIViewAnimationOptionTransitionCrossDissolve, but that does not animate change. Just instantly changes to new tint color after the animation duration
    • I had an idea of implementing new iOS 7 custom transition calculating and changing color of navbar during progress, but that seems to be big overkill (specially if I want to keep original animation appearance everywhere)

    感谢大家的任何想法和答案

    Thank you everyone for any ideas and answers

    推荐答案

    您可以使用 UIViewControllerTransitionCoordinator 获得这个。


    1. 将示例代码复制到 AController 并自定义颜色。

    2. 复制示例代码到 BController 并自定义颜色。

    3. 就是这样!在 UINavigationController 的push / pop转换期间, AController 的样式将平滑地淡入/ $ c> BController 的样式。

    1. Copy the example code to the AController and customize the colors.
    2. Copy the example code to the BController and customize the colors.
    3. That's it! During UINavigationController's push/pop transition, the AController's style will smoothly fade in/out to BController's style.

    示例代码:

    -(void) viewWillAppear:(BOOL)animated{
        [super viewWillAppear:animated];
    
        [[self transitionCoordinator] animateAlongsideTransition:^(id<UIViewControllerTransitionCoordinatorContext> context) {
            self.navigationController.navigationBar.translucent = NO;
            self.navigationController.navigationBar.barStyle = UIBarStyleDefault;
    
            // text color
            [self.navigationController.navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName : [UIColor whiteColor]}];
    
            // navigation items and bar button items color
            self.navigationController.navigationBar.tintColor = [UIColor whiteColor];
    
            // background color
            self.navigationController.navigationBar.barTintColor = [UIColor blueColor];
        } completion:nil];
    }
    

    这篇关于iOS 7 UINavigationController NavBar每个控制器的颜色动画的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

    08-16 06:33