UIView动画淡入淡出会导致Alpha降至1.0以下? [英] UIView animated crossfade causes alpha to drop below 1.0?

查看:115
本文介绍了UIView动画淡入淡出会导致Alpha降至1.0以下?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用UIView动画在两个视图之间进行淡入淡出。我注意到了以下令人惊讶的事实:



如果我在同一个地方有(说)两个相同的视图,并且我为它们之间的交叉淡入淡出设置了动画(例如,在同一动画中,一个的alpha值从0.0到1.0,而另一个的alpha值从1.0变为0.0),在动画期间,可见结果在动画期间的弧度稍微低于不透明的程度-这是一个明显的伪像,可以通过放置交叉淡化视图后的其他视图(在动画中短暂可见,然后再次被遮盖)。



我希望(使用 any 动画时序曲线),完美地配对了0-> 1和1-> 0的alpha转换总会得到1.0的净alpha值,在这种测试情况下,我永远不会看到alpha的任何可见变化,但是我知道。 / p>

你知道这里发生了什么吗?我可以解决这个问题以获得修复,但是我对混合概念上我缺少的东西最感兴趣。



谢谢!

解决方案

两个Alpha值总计为1.0的堆叠视图无法完成您认为的工作。它们是相乘的,而不是相加的。



让我们一次取一大块。这是100%闪耀的背景:

  bg 
| ======>
| ======>
| ======>
| ======>

现在让我们在顶部添加另一个视图,即不透明度为50%。这意味着它可以让50%的背景通过 b
$ b

  bg 50%
| = == | ===>
| === |
| === | ===>
| === |

如果我们在顶部还有50%的视图怎么办?

  bg 50%50%
| === | === | ===>
| === | |
| === | === |
| === | |

另外后面的50%的东西通过了。这意味着50%×50%= 25%的背景层仍将显示出来。



现在,您真正想做什么?您希望新视图能够平滑显示,并且通过旧视图的数量也越来越多。因此,只需堆叠两个视图,然后淡出顶部的视图,但将底部始终保持100%的透明度。否则,您将在动画播放期间显示某些背景。


I'm crossfading between two views using UIView animation. I've noticed the following surprising fact:

If I have (say) two identical views in an identical place, and I animate a cross fade between them (e.g. animate the alpha from 0.0 to 1.0 on one while going from 1.0 to 0.0 on the other, in the same animation), during the animation, the visible result arcs slightly below opaque during the animation-- this is a noticeable artifact and can be verified by putting some other view behind the crossfaded views (it becomes visible briefly during the animation before being obscured again).

I would expect (using any animation timing curve) that perfectly paired 0->1 and 1->0 alpha transitions would always add up to a net alpha of 1.0, and that in this test situation, I should never see any visible change in alpha, yet I do.

Any idea what's going on here? I could hack around this for a "fix", but I'm mostly interested in what I'm missing conceptually in the blending.

Thanks!

解决方案

Two stacked views with alphas adding up to 1.0 doesn't do what you think it does. They are multiplied, not added.

Let's take it a chunk at a time. Here's a background, shining through 100%:

bg
|======>
|======>
|======>
|======>

Now let's add another view on top, 50% opacity. That means it lets 50% of the background through

bg 50%
|===|===>
|===|
|===|===>
|===|

What if we have another 50% view on top?

bg 50% 50%
|===|===|===>
|===|   |
|===|===|
|===|   |

Another 50% of the stuff behind is passed through. This means that 50% × 50% = 25% of the background layer will still be showing through.

Now, what do you really want to do? You want the new view to appear smoothly, an increasing amount passing through the old view. So just stack the two views, and fade out the top one, but leave the bottom at 100% opacity the whole time. Otherwise you'll be showing some of the background through during the animation.

这篇关于UIView动画淡入淡出会导致Alpha降至1.0以下?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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