本文介绍了iOS 7 UINavigationController NavBar每个控制器的颜色动画的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有任何方法可以有不同的 c> [UIView transitionWithView:...] $>更改 barTintColor c $ c>阻塞与 UIViewAnimationOptionTransitionCrossDissolve ,但不是动画变化。
- 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 获得这个。
- 将示例代码复制到 AController 并自定义颜色。
- 复制示例代码到 BController 并自定义颜色。
- 就是这样!在 UINavigationController 的push / pop转换期间, AController 的样式将平滑地淡入/ $ c> BController 的样式。
- Copy the example code to the AController and customize the colors.
- Copy the example code to the BController and customize the colors.
- 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每个控制器的颜色动画的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!