Movatterモバイル変換


[0]ホーム

URL:


Skip to content
DEV Community
Log in Create account

DEV Community

Midhet Sulemani
Midhet Sulemani

Posted on

     

Core Animations in Swift

Apple's documentation says that:Core Animation provides high frame rates and smooth animations without burdening the CPU and slowing down your app. Most of the work required to draw each frame of an animation is done for you. You configure animation parameters such as the start and end points, and Core Animation does the rest, handing off most of the work to dedicated graphics hardware, to accelerate rendering.

The main difference between UIView animations and Core Animations is that UIView animations animate the whole view whereas Core Animations have the ability to animate each sublayer of the UIView.

You can find all the various types of animations enabled by Core Animation in iOShere.


Let's continue with adding a Core Animation to the TODO Application we built in the previous post of this series, or you can find the starter projecthere.


We are going to build a live color changing gradient animation to theAdd ToDo button.

Gradient animation preview

Let's create a method calledanimateGradient() inNewTodoViewController.swift.

Add the following code in the method:

funcanimateGradient(){// cycle through all the colors, feel free to add more to the setifcurrentGradient<gradientSet.count-1{currentGradient+=1}else{currentGradient=0}// animate over 3 secondsletgradientChangeAnimation=CABasicAnimation(keyPath:"colors")gradientChangeAnimation.duration=3.0gradientChangeAnimation.toValue=gradientSet[currentGradient]gradientChangeAnimation.fillMode=CAMediaTimingFillMode.forwardsgradientChangeAnimation.isRemovedOnCompletion=falsegradientChangeAnimation.delegate=selfgradient.add(gradientChangeAnimation,forKey:"gradientChangeAnimation")}
Enter fullscreen modeExit fullscreen mode

And now you have created your first Core Animation!

Core Animation is a very powerful library and you can do almost all the animations your heart desires. So get a move on and explore the full potential of Core Animations!

That's it for this series on animations and stay tuned for more tips and tricks in iOS :)

That's a wrap

Top comments(0)

Subscribe
pic
Create template

Templates let you quickly answer FAQs or store snippets for re-use.

Dismiss

Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment'spermalink.

For further actions, you may consider blocking this person and/orreporting abuse

iOS Developer by profession. Interested in UX Design, AI and Robotics. I also enjoy watching random YouTube videos, reading, going out for walks and doing some graphic design on the side.
  • Location
    Kuwait
  • Education
    BE (Computer Science)
  • Work
    iOS Developer
  • Joined

More fromMidhet Sulemani

DEV Community

We're a place where coders share, stay up-to-date and grow their careers.

Log in Create account

[8]ページ先頭

©2009-2025 Movatter.jp