UINavigationBar change Tint color with animation(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.
有很多代码检查 when 是否消失,我什至编写了一个名为 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 颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:UINavigationBar 用动画改变 Tint 颜色
基础教程推荐
- navigator.geolocation.getCurrentPosition 在 Android 浏览器上 2022-01-01
- libGDX 从精灵或纹理中获取像素颜色 2022-01-01
- Android:getLastKnownLocation(LocationManager.NETWORK_PROVIDER 2022-01-01
- 通过重定向链接在 Google Play 中打开应用 2022-01-01
- 如何从 logcat 中删除旧数据? 2022-01-01
- iPhone - 获取给定地点/时区的当前日期和时间并将其与同一地点的另一个日期/时间进行比较的正确方法 2022-01-01
- NSString intValue 不能用于检索电话号码 2022-01-01
- Cocos2d iPhone 非矩形精灵触摸检测 2022-01-01
- AdMob 广告未在模拟器中显示 2022-01-01
- iOS4 创建后台定时器 2022-01-01
