Advertisement
Guest User

Untitled

a guest
Feb 10th, 2016
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.06 KB | None | 0 0
  1. //: Playground - noun: a place where people can play
  2.  
  3. import UIKit
  4. import XCPlayground
  5.  
  6. let aView = UIView(frame: CGRectMake(0, 0, 200, 200))
  7. aView.backgroundColor = UIColor.whiteColor()
  8.  
  9. let aLayer = CALayer()
  10. aLayer.bounds = CGRectMake(0, 0, 100, 100)
  11. aLayer.position = aView.center
  12. aLayer.backgroundColor = UIColor.blueColor().CGColor
  13. aView.layer.addSublayer(aLayer)
  14.  
  15. aLayer.opacity = 1.0
  16. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, Int64(0.5 * Double(NSEC_PER_SEC))), dispatch_get_main_queue(), { () -> Void in
  17.  
  18. // implicit
  19. // aLayer.transform = CATransform3DMakeRotation(CGFloat(M_PI_4), 0, 0, 1)
  20.  
  21. // explicit
  22. let animation = CABasicAnimation()
  23. animation.keyPath = "transform"
  24. animation.fromValue = NSValue(CATransform3D: aLayer.transform)
  25. animation.toValue = NSValue(CATransform3D: CATransform3DMakeRotation(CGFloat(M_PI_4), 0, 0, 1))
  26. animation.duration = 1.0
  27. aLayer.transform = CATransform3DMakeRotation(CGFloat(M_PI_4), 0, 0, 1)
  28. aLayer.addAnimation(animation, forKey: "rotation")
  29. })
  30.  
  31. XCPlaygroundPage.currentPage.liveView = aView
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement