Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
304 views
in Technique[技术] by (71.8m points)

swift - Animated color transition

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.

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?

enter image description here

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
    }
}
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

It is possible to achieve but it is not straight forward.

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.

Your view should look like this (RedView is the top most view):

  • [ RedView ]
  • [ WhiteLabelsView ]
  • [ BlackLabelsView ]

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...