Slide 1

Slide 1 text

TRANSFORMATIONS IOS BOOK CLUB JASDEV SINGH

Slide 2

Slide 2 text

AFFINE TRANSFORMATIONS > Rotation > CGAffineTransformMakeRotation(_:) > Scaling > CGAffineTransformMakeScale(_:_:) > Translations > CGAffineTransformMakeTranslation(_:_:)

Slide 3

Slide 3 text

UIView transform PROPERTY Really just a wrapper on the underlying CALayer feature, affineTransform.

Slide 4

Slide 4 text

COMPOSING TRANSFORMATIONS Core Graphics provides functions that take existing transformations and applies another on top of it. > CGAffineTransformRotate(_:_:) > CGAffineTransformScale(_:_:_:) > CGAffineTransformTranslate(_:_:_:) > CGAffineTransformConcat(_:_:)

Slide 5

Slide 5 text

SAMPLE TRANSFORMATION > 50% scale > Rotate 30 degrees > Vertical translation by 200 points public func +(lhs: CGAffineTransform, rhs: CGAffineTransform) -> CGAffineTransform { return CGAffineTransformConcat(lhs, rhs) }

Slide 6

Slide 6 text

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) } }

Slide 7

Slide 7 text

No content

Slide 8

Slide 8 text

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:

Slide 9

Slide 9 text

3D TRANSFORMS The transform property on CALayer is of type CATransform3D. > CATransform3DMakeRotation(_:_:_:_:) > CATransform3DMakeScale(_:_:_:) > CATransform3DMakeTranslation(_:_:_:)

Slide 10

Slide 10 text

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 .

Slide 11

Slide 11 text

By default, . To apply perspective, set to , where is the distance between the imaginary camera and the screen, in points. usually works well.

Slide 12

Slide 12 text

sublayerTransform PROPERTY A CATranmsform3D property on CALayer that allows you to apply a transform to all sublayers!

Slide 13

Slide 13 text

doubleSided PROPERTY