动画色彩过渡 [英] Animated color transition
问题描述
这是一个关于如何解决这个问题的更普遍的问题.如下图所示,我在堆栈视图中有 4 个 textLabel,堆栈视图后面是一个红色的 UIVew.
Hi this is a more general question on how to approach this. As you can see in the image below I have 4 textLabels in a stack view, and behind the stack view is a red UIVew.
当 UIView 滑过下一个文本时,我希望文本在视图位于文本上时改变颜色.我不想要一个突然的变化,而是一个由红色 UIView 驱动的遮罩/滑动颜色效果.
When the UIView slides over the next text, I would like the text to change color whenever the view is over the text. I don't want an abrupt change, but rather a masking/sliding color effect, driven by the red UIView.
目前只有在过渡完成后才会改变颜色.
Currently its only changing colours once the transition is done.
你会如何处理这个问题?
How would you approach this?
应要求提供基本滑动代码:
on request the basic sliding code:
func scrollViewDidScroll(_ scrollView: UIScrollView) {
if isScrolling {
let factor = (scrollView.contentOffset.x/UIScreen.main.bounds.width) * (margin.left/2)
self.navigationBar.indicatorConstraint.constant = (scrollView.contentOffset.x / 4) - factor
}
}
推荐答案
可以实现,但不是直截了当的.
It is possible to achieve but it is not straight forward.
您必须添加白色和黑色文本 UILabel.这些标签包含在视图中,例如 WhiteLabelsView 和 BlackLabelsView.红色视图应该屏蔽 WhiteLabelsView,BlackLabelsView 应该在后面
You would have to add white and black text UILabels. These labels contained on a view, for example the WhiteLabelsView and the BlackLabelsView. The red view should mask the WhiteLabelsView, and the BlackLabelsView should be behind them.
您的视图应如下所示(RedView 是最顶部的视图):
Your view should look like this (RedView is the top most view):
- [红色视图]
- [白标签视图]
- [ 黑标签视图 ]
这篇关于动画色彩过渡的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!