Skip to content

Instantly share code, notes, and snippets.

@jkosoy
Last active February 29, 2016 01:45
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 jkosoy/fa0ab3b4f606b98d7f1d to your computer and use it in GitHub Desktop.
Save jkosoy/fa0ab3b4f606b98d7f1d to your computer and use it in GitHub Desktop.
CFAAction+AHEasing example
let foo = UIView(frame: CGRect(x: 0, y: 0, width: 100, height: 100))
foo.center = view.center
foo.layer.backgroundColor = UIColor.blueColor().CGColor
foo.layer.anchorPoint = CGPoint(x: 0.5, y: 0.5)
view.addSubview(foo)
foo.layer.opacity = 1.0
let fade = CFAAction.fade(fromValue: 0, toValue: 1, time: 2.5, curveType: CurveType.CurveTypeQuintic, easeType: EaseType.EaseTypeOut)
let scale = CFAAction.scale(fromValue: 1.0, toValue: 2.5, time: 1, curveType: CurveType.CurveTypeBounce, easeType: EaseType.EaseTypeOut)
let rotate = CFAAction.rotate(fromValue: 0.0, toValue: CGFloat( M_PI ), time: 1, curveType: CurveType.CurveTypeBounce, easeType: EaseType.EaseTypeOut)
// running a custom block. not perfect right now, but it works.
let custom = CFAAction.customActionWithDuration(0.1, actionBlock: { layer, elapsedTime in
if(elapsedTime == 0.1) {
print("Executing custom code in between steps!")
}
})
let group = CFAAction.sequence([ scale, rotate ])
let color = CFAAction.colorize(fromValue: UIColor.blueColor(), toValue: UIColor.redColor(), time: 2.5, curveType: CurveType.CurveTypeLinear, easeType: EaseType.EaseTypeInOut)
let sequence = CFAAction.sequence([ fade, CFAAction.waitForDuration(1.0), custom, group, color ])
foo.layer.runAction(sequence) {
print("Animation is complete!")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment