Last active
February 29, 2016 01:45
-
-
Save jkosoy/fa0ab3b4f606b98d7f1d to your computer and use it in GitHub Desktop.
CFAAction+AHEasing example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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