0
0
iOS Swiftmobile~3 mins

Why Custom animation timing in iOS Swift? - Purpose & Use Cases

Choose your learning style9 modes available
The Big Idea

What if your app's animations could feel as smooth and natural as real life?

The Scenario

Imagine you want a button to move smoothly across the screen, but at different speeds during the journey, like speeding up then slowing down, just like a car on a road trip.

The Problem

Using only basic animation tools, you get a boring, constant speed that feels unnatural and robotic. It's hard to make animations feel alive or match the mood you want.

The Solution

Custom animation timing lets you control exactly how fast or slow parts of your animation run. You can create smooth, natural movements that feel real and engaging.

Before vs After
Before
UIView.animate(withDuration: 2.0, delay: 0, options: [.curveLinear], animations: {
  button.frame.origin.x += 200
}, completion: nil)
After
let timing = CAMediaTimingFunction(name: .easeInEaseOut)
let animation = CABasicAnimation(keyPath: "position.x")
animation.timingFunction = timing
animation.duration = 2.0
animation.byValue = 200.0
animation.fillMode = .forwards
animation.isRemovedOnCompletion = false
button.layer.add(animation, forKey: nil)
What It Enables

It enables animations that tell a story with motion, making apps feel polished and delightful.

Real Life Example

Think of a weather app where the sun rises slowly, speeds up, then gently sets, creating a calming effect that matches the time of day.

Key Takeaways

Basic animations move at a constant speed, which can feel dull.

Custom timing lets you shape the speed curve for natural motion.

This makes your app's animations more engaging and professional.