我可以淡入淡出/动画 UIToolbar 的tintColor 吗?
我正在尝试对 UIToolbar 的tintColor 属性进行动画处理,将其从一种tintColor 更改为另一种tintColor。
这是我正在尝试的代码。不幸的是,这种变化是立即发生的,并且不会从绿色褪成蓝色。这很奇怪,因为我知道苹果在网络共享或打电话时会淡出并“脉冲”工具栏色调颜色。那么为什么这不起作用呢?
// set initial tint color
myBottomToolBar.tintColor = [UIColor colorWithRed:0.15 green:0.95 blue:0.15 alpha:0.6];
//animation stuff
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:1.95];
[UIView setAnimationDelegate:self];
//thing to animate
myBottomToolBar.tintColor = [UIColor colorWithRed:0.15 green:0.35 blue:0.45 alpha:0.6];
//animation stuff
[UIView commitAnimations];
I am trying to animate a UIToolbar's tintColor property, to change it from one tintColor to another.
Here is the code I am trying. Unfortunately, the change occurs immediately and does not fade from green to blue. This is strange because I know Apple fades and "pulses" toolbar tint colors when tethering or on a phone call. So why doesn't this work?
// set initial tint color
myBottomToolBar.tintColor = [UIColor colorWithRed:0.15 green:0.95 blue:0.15 alpha:0.6];
//animation stuff
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:1.95];
[UIView setAnimationDelegate:self];
//thing to animate
myBottomToolBar.tintColor = [UIColor colorWithRed:0.15 green:0.35 blue:0.45 alpha:0.6];
//animation stuff
[UIView commitAnimations];
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
色调颜色无法通过公共 API 设置动画。您可以通过手动更改计时器上的色调颜色来解决此问题。您必须插入中间颜色级别。
The tint color in not animatable through public APIs. You can work around this by manually changing the tint color on a timer. You would have to interpolate the intermediate color levels.
每个
UIView
都有一个 tintAdjustmentMode:例如,如果您需要调暗当前的tintColor(dim = 灰色),只需使用以下代码:
这会将tintColor 动画设置为灰色并将其调暗。
如果您想将tintColor设置为您自己的自定义颜色:
Each
UIView
has a tintAdjustmentMode:For example, if you need to dim the current tintColor (dim = grey color) just use the code below:
This will animate the tintColor to grey and will dim it.
If you want to animate the tintColor to your own custom color:
为了供将来参考,这是我有点仓促的动画色调解决方案。我确信有更聪明的方法可以通过类别和 RGB 值的结构来做到这一点。我很着急好吗?!
UITabBarController 子类:
.
For future reference, here's my somewhat hasty solution for animating tint. I'm sure there are more clever ways of doing this with categories and a struct for the rgb values yadda yadda. I was in a hurry, OK?!
UITabBarController subclass:
.
NSTimer
及其设置对于一个简单的动画来说是大量的工作。这是我使用调度的解决方案,我只是通过更改色调颜色的 alpha 值来淡入和淡出UIBarButtonItem
:线性曲线可能有点明显,但我有兴趣先尝试 CADisplayLink在进行任何更改之前。
NSTimer
and it's setup is a lot of work for a simple animation. Here's my solution using dispatch, I'm just fading aUIBarButtonItem
in and out by changing the alpha value of the tint color:The linear curve can be a little noticeable but I'm interested in trying CADisplayLink first before making any changes.