iOS 7 UINavigationController NavBar每个控制器的颜色动画 [英] iOS 7 UINavigationController NavBar per controller color animation
问题描述
有任何方法可以有不同的 barTintColor
UINavigationController
' UINavigationBar
在不同的推动控制器上使用平滑的颜色过渡动画?
Is there any way to have different barTintColor
of UINavigationController
's UINavigationBar
on different pushed controllers with smooth color transition animation?
我想要一个平滑的动画 UINavigationBar 在
UINavigationController
的推/弹动动画,最理想的是 based controller pop)。
I'd like to have a smooth animation of UINavigationBar
's tint color during UINavigationController
's push/pop animation and ideally also interactive pop (gesture based controller pop).
为什么需要这个?我想在导航堆栈中有一个控制器,以具有不同的颜色指示某些任务的状态(红/绿等)。
Why do I need this? I'd like to have 1 controller in the navigation stack to have different tint color indicating status of some task (red / green etc.).
我试过的far:
-
viewWillAppear
(查看生命周期)方法,但没有办法动画barTintColor
(如setBarTintColor:animated:
) - code> barTintColor 在
[UIView animation ...]
块,但是只是奇怪地动画框架 c> [UIView transitionWithView:...] $>更改barTintColor
c $ c>阻塞与UIViewAnimationOptionTransitionCrossDissolve
,但不是动画变化。 - 我想在实施新的iOS 7自定义过渡计算和改变导航条的颜色,但是似乎是大的过度杀戮特别是如果我想保持原始动画出现无处不在)
viewWillAppear
(view lifecycle) methods, but there is no way to animate thebarTintColor
(likesetBarTintColor: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 withUIViewAnimationOptionTransitionCrossDissolve
, 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, theAController
's style will smoothly fade in/out toBController
'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每个控制器的颜色动画的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!