Skip to content

Instantly share code, notes, and snippets.

@jquave
Created June 17, 2016 22:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jquave/380403b6ec270c89888b973d26f23269 to your computer and use it in GitHub Desktop.
Save jquave/380403b6ec270c89888b973d26f23269 to your computer and use it in GitHub Desktop.
// fill with yellow
rectShape.fillColor = UIColor.yellowColor().CGColor
// 1
// begin with a circle with a 50 points radius
let startShape = UIBezierPath(roundedRect: bounds, cornerRadius: 50).CGPath
// animation end with a large circle with 500 points radius
let endShape = UIBezierPath(roundedRect: CGRect(x: -450, y: -450, width: 1000, height: 1000), cornerRadius: 500).CGPath
// set initial shape
rectShape.path = startShape
// 2
// animate the `path`
let animation = CABasicAnimation(keyPath: "path")
animation.toValue = endShape
animation.duration = 1 // duration is 1 sec
// 3
animation.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseOut) // animation curve is Ease Out
animation.fillMode = kCAFillModeBoth // keep to value after finishing
animation.removedOnCompletion = false // don't remove after finishing
// 4
rectShape.addAnimation(animation, forKey: animation.keyPath)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment