Hero: How can I from A UILabel to B UILabel with different colors?

Created on 1 Mar 2018  路  3Comments  路  Source: HeroTransitions/Hero

Hi
How can I from A Label to B Label with different colors?

For example
A Label with red color in VC1, and B Label with blue color in VC2, how can I translate them by Hero.

Thanks and best regards

question

Most helpful comment

@pxwinter I came across a similar issue whereby:

  • if my destination ViewController is instantiated via Storyboard, this scenario of old text artifact being visible throughout duration is not present
  • however, if I recreate the same ViewController manually, and set it up in code the same way it is setup in storyboard, then I would get the same result you posted.

After some debugging, the solution I found is simple. In Storyboard when you add a UILabel, Xcode by default set's it's isOpaque property to false.

However, if you create a UILabel in code, it's isOpaque property for some reason is set to true.

In Hero's MatchPreprocessor is appears to behave differently depending on whether the view is opaque or not, on line 44:

let isNonOpaque = !fv.isOpaque || fv.alpha < 1 || !tv.isOpaque || tv.alpha < 1

So to solve my problem it was enough to simply set label.isOpaque = false on the destination label.

All 3 comments

Not sure if I understand your question clearly. But setting the heroId to be the same for both label should do it right?

@lkzhao Thanks for your feedback, could you please look at this attach file, I record a demo video.
In the progress the animation, the red label didn't fade away. How can I add a fade animation on red label (opacity from 1 to 0)
demo1

Thanks and best regards

@pxwinter I came across a similar issue whereby:

  • if my destination ViewController is instantiated via Storyboard, this scenario of old text artifact being visible throughout duration is not present
  • however, if I recreate the same ViewController manually, and set it up in code the same way it is setup in storyboard, then I would get the same result you posted.

After some debugging, the solution I found is simple. In Storyboard when you add a UILabel, Xcode by default set's it's isOpaque property to false.

However, if you create a UILabel in code, it's isOpaque property for some reason is set to true.

In Hero's MatchPreprocessor is appears to behave differently depending on whether the view is opaque or not, on line 44:

let isNonOpaque = !fv.isOpaque || fv.alpha < 1 || !tv.isOpaque || tv.alpha < 1

So to solve my problem it was enough to simply set label.isOpaque = false on the destination label.

Was this page helpful?
0 / 5 - 0 ratings