Skip to content

Instantly share code, notes, and snippets.

@cgoldsby
Created September 21, 2016 22:14
Show Gist options
  • Save cgoldsby/d489687f2788499adb514370cf725721 to your computer and use it in GitHub Desktop.
Save cgoldsby/d489687f2788499adb514370cf725721 to your computer and use it in GitHub Desktop.
One last thing, as a bonus, is we have CATransitions. You’ll notice in a number of these animations that the text transitions between states is in a little bit more of an elegant fashion than our normal set text. Set text is very effective, but when you replace the text within about one frame, it’s very jarring. When you’re fading colors around your text, we really want to consider fading the text as well.
extension CATransition {
static func simpleFade() -> CATransition {
let fadeTransition = CATransition()
fadeTransition.duration = 0.125
fadeTransition.type = kCATransitionFade
fadeTransition.timingFunction = CAMediaTimingFunction(
name: kCAMediaTimingFunctionEaseInEaseOut)
return fadeTransition
}
}
What we have right here is a simple category or extension on a CATransaction for a factory method. This one creates a simple fade transition. We can apply this to our UI label. This looks very similar to our basic animations. We have a duration, we have a timing function, but we also have a type. In this case, we’re going to call it a fade type. And that’s all there is to it. I just return this simple fade.
let simpleFadeTransition = CATransition.simpleFade()
titleLabel.layer.addAnimation(simpleFadeTransition,
forKey: "changeTextTransition")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment