为UINavigationBar的barTintColor设置动画 [英] Animate a UINavigationBar's barTintColor

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

问题描述

我正在处理的应用在推送新视图控制器时会更改其导航栏的 barTintColor 。现在我们在目标视图控制器的 viewWillAppear:方法中设置该颜色,但是我们遇到了一些问题。

The app I'm working on changes the barTintColor of its navigation bar when pushing new view controllers. Right now we set that colour in the destination view controller's viewWillAppear:method, but we have a few issues with that.

按照我们现在这样做的方式,导航栏的颜色会突然变化,而其余的条形内容会像往常一样动画。我喜欢的是酒吧在源颜色和目标颜色之间淡入淡出。有没有办法用公共Cocoa Touch API实现这一目标?

With the way we're doing this right now, the navigation bar's colour changes abruptly, while the rest of the bar content animates as usual. What I'd like is for the bar to fade between the source and destination colour. Is there any way to achieve this with public Cocoa Touch APIs?

推荐答案

您可以添加与时间和动画曲线相匹配的额外动画使用 UIViewControllerTransitionCoordinator 进行视图控制器转换。

You can add extra animations that match the timing and animation curve of the view controller transition using UIViewControllerTransitionCoordinator.

在视图控制器的动画开始后,视图控制器的 transitionCoordinator 将被设置为(所以在 viewWillAppear 显示的视图控制器)。在转换协调员处使用 animateAlongsideTransition:completion:添加任何额外的动画。

A view controller's transitionCoordinator will be set after a view controller's animation has started (so in viewWillAppear of the presented view controller). Add any extra animations using animateAlongsideTransition:completion: on the transition coordinator.

示例:

[[self transitionCoordinator] animateAlongsideTransition:^(id<UIViewControllerTransitionCoordinatorContext> context) {
    self.navigationController.navigationBar.translucent = NO;
    self.navigationController.navigationBar.barStyle = UIBarStyleBlack;
    self.navigationController.navigationBar.tintColor = [UIColor whiteColor];
    self.navigationController.navigationBar.barTintColor = [UIColor redColor];
} completion:nil];

这篇关于为UINavigationBar的barTintColor设置动画的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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