两个 UILabels 之间的交叉淡入淡出
假设我有两个 UILabel
(labelOne
和 labelTwo
),我需要在两个标签之间交叉淡入淡出。达到这种效果的最佳方法是什么?
我尝试使用 [UIView beginAnimations:@"crossFade" context:nil];
等淡出 labelOne
然后淡入 labelTwo
但当两个标签都处于低不透明度并且您可以看穿两者时,就会出现相当明显的间隙。我需要一个漂亮干净的交叉淡入淡出效果。我有一种感觉,我需要使用 CABasicAnimation,但我希望得到一些指导。提前致谢!
Say that I have two UILabel
s (labelOne
and labelTwo
) and I need to cross-fade between the two labels. What is the best way of achieving this effect?
I have tried using [UIView beginAnimations:@"crossFade" context:nil];
etc. to fade-out labelOne
and then fade-in labelTwo
but there is a fairly noticeable gap when both labels are at a low opacity and you can see through both. I need a nice clean cross-fade effect instead. I have a feeling that I will need to use CABasicAnimation
but I would appreciate some guidance. Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这将使一个标签(或任何视图)淡出,同时使另一个标签淡入。动画进行到一半时,两者的不透明度都为 50%。要单独控制 Alpha,请为每个标签使用单独的动画并延迟其中一个。
This will fade one label (or any view) out while fading the other in. Half way through the animation, both will be at 50% opacity. To control the alpha separately, use a separate animation for each label and delay one of them.
您可以摆弄动画曲线,尝试找到可接受的外观,但我认为您会做得更好,只需在两个标签下方保留第三个视图,以在淡入淡出时保持背景外观。
如果您的意思是您可以同时看到两个标签不是同时淡出,而是快速淡出到标签开始不清楚的程度,请用相同淡入淡出级别的新标签替换它,然后快速淡出到完全可见性。
我说“淡入淡出”,但将背景色视图放在标签顶部并继续使该视图更加不透明,切换下面的标签,然后再次将其淡入透明,看起来也非常好。
You could fiddle around with the animation curve try and find an acceptable look but I think you will do better just maintaining a third view underneath both labels to maintain the background appearance while the fades happen.
If you mean that you can see both labels at once don't fade concurrently, but fade quickly to a point at which the label begins to be unclear, replace it with the new label at the same fade level, then fade it up quickly to full visibility.
I say "fade" but it could also look very good to put a background-colored view on top of the labels and proceed to make that view more opaque, switching the labels underneath, then fading it to transparent again.
我已经实现了类似的东西并且效果很好。
I've implemented something like this and it works very well.