Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Tranformations - Core Animation

Tranformations - Core Animation

Chapter review from Nick Lockwood's Core Animation book at Tumblr's iOS Book Club

Jasdev Singh

March 22, 2016
Tweet

More Decks by Jasdev Singh

Other Decks in Technology

Transcript

  1. COMPOSING TRANSFORMATIONS Core Graphics provides functions that take existing transformations

    and applies another on top of it. > CGAffineTransformRotate(_:_:) > CGAffineTransformScale(_:_:_:) > CGAffineTransformTranslate(_:_:_:) > CGAffineTransformConcat(_:_:)
  2. SAMPLE TRANSFORMATION > 50% scale > Rotate 30 degrees >

    Vertical translation by 200 points public func +(lhs: CGAffineTransform, rhs: CGAffineTransform) -> CGAffineTransform { return CGAffineTransformConcat(lhs, rhs) }
  3. import UIKit class ViewController: UIViewController { let view1 = UIView()

    override func viewDidLoad() { super.viewDidLoad() view1.backgroundColor = .greenColor() view1.frame = CGRect(origin: view.center, size: CGSize(width: 150, height: 150)) view.addSubview(view1) let transform = CGAffineTransformIdentity + CGAffineTransformMakeScale(0.5, 0.5) + CGAffineTransformMakeRotation(CGFloat(M_PI) / 180 * 30) + CGAffineTransformMakeTranslation(0, 200) view1.layer.setAffineTransform(transform) } }
  4. ARTISANAL TRANSFORMATIONS If you need to to make custom affine

    transformations that aren't built into Core Graphics, you can directly set values on the transformation matrix:
  5. 3D TRANSFORMS The transform property on CALayer is of type

    CATransform3D. > CATransform3DMakeRotation(_:_:_:_:) > CATransform3DMakeScale(_:_:_:) > CATransform3DMakeTranslation(_:_:_:)
  6. Perspective Projections By default, Core Animation uses isometric projections, which

    preserves parallel lines in 3D space. To give our 3D transformations a sense of depth, we have to add a perspective transform .
  7. By default, . To apply perspective, set to , where

    is the distance between the imaginary camera and the screen, in points. usually works well.