Skip to content

Instantly share code, notes, and snippets.

@marcusficner
Created February 10, 2016 12:37
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 marcusficner/b2cae33be73f83789dfa to your computer and use it in GitHub Desktop.
Save marcusficner/b2cae33be73f83789dfa to your computer and use it in GitHub Desktop.
Xcode playground with live view to quickly test animations
//: Playground - noun: a place where people can play
import UIKit
import XCPlayground
let aView = UIView(frame: CGRectMake(0, 0, 200, 200))
aView.backgroundColor = UIColor.whiteColor()
let aLayer = CALayer()
aLayer.bounds = CGRectMake(0, 0, 100, 100)
aLayer.position = aView.center
aLayer.backgroundColor = UIColor.blueColor().CGColor
aView.layer.addSublayer(aLayer)
aLayer.opacity = 1.0
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, Int64(0.5 * Double(NSEC_PER_SEC))), dispatch_get_main_queue(), { () -> Void in
// implicit
// aLayer.transform = CATransform3DMakeRotation(CGFloat(M_PI_4), 0, 0, 1)
// explicit
let animation = CABasicAnimation()
animation.keyPath = "transform"
animation.fromValue = NSValue(CATransform3D: aLayer.transform)
animation.toValue = NSValue(CATransform3D: CATransform3DMakeRotation(CGFloat(M_PI_4), 0, 0, 1))
animation.duration = 1.0
aLayer.transform = CATransform3DMakeRotation(CGFloat(M_PI_4), 0, 0, 1)
aLayer.addAnimation(animation, forKey: "rotation")
})
XCPlaygroundPage.currentPage.liveView = aView
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment