Created
February 10, 2016 12:37
-
-
Save marcusficner/b2cae33be73f83789dfa to your computer and use it in GitHub Desktop.
Xcode playground with live view to quickly test animations
This file contains 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
//: 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