UINavigationBar用动画改变Tint颜色 [英] UINavigationBar change Tint color with animation

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

问题描述

是否可以通过动画更改色调以获得更平滑的效果?

Is it possible to change the tint with animation for a smoother effect?

这对我不起作用:

[UIView beginAnimations:nil context:nil];
[self.navigationController.navigationBar setTintColor:[UIColor greenColor]];
[UIView commitAnimations];

我不确定是否可以使用原生苹果组件,因为我猜他们会使用CG生成渐变...只是想在我开始构建自己的解决方案之前找出...

I a not sure if it is even possible using native apple components as I guess they will be using CG to generate the gradient ... just want to find out before I'll start building my own solution ...

干杯们:)

推荐答案

你不会相信我经历的那么长的时间才能做到这一点;让我感到恼火的是,这不是iOS的一个特色,而且tintColor的转换看起来很难看,而推动/弹出一个viewController的动画是如此顺利。

You wouldn't believe the length I went through to actually make that possible; it annoyed me to no end that this isn't a stock iOS feature and that transition of tintColor look ugly while the animation to push/pop a viewController is so smooth.

有很多代码在淡出时检查,我甚至编写了一个名为PSPDFNavigationAppearanceSnapshot的类来保存弹出时的导航状态。 (我从很棒的 NimbusKit 中得到了这个想法)

There'a lot of code that checks when to fade, and I've even written a class called PSPDFNavigationAppearanceSnapshot to preserve the navigation state when being popped. (I got that idea from the awesome NimbusKit)

实际动画很简单:

[self.navigationController.navigationBar.layer addAnimation:PSPDFFadeTransition() forKey:nil];

CATransition *PSPDFFadeTransition(void) {
    return PSPDFFadeTransitionWithDuration(0.25f);
}

CATransition *PSPDFFadeTransitionWithDuration(CGFloat duration) {
    CATransition *transition = [CATransition animation];
    transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
    transition.type = kCATransitionFade;
    transition.duration = duration;
    return transition;
}

您可以进一步压缩该代码;它来自我的iOS PDF库PSPDFKit,我在各个地方使用淡入淡出,因此辅助函数。

You can compact that code even more; it's a snipped from my iOS PDF library PSPDFKit and I use the fade in various places, thus the helper functions.

这篇关于UINavigationBar用动画改变Tint颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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