CGAffineTransformConCat/ CGAffineTransformMakeScale in Swift 3

Viewed 5078

I'm trying to update a part of a function for swift 3:

  let newLabelOffset = CGFloat(direction.rawValue) * originalFrame.size.height/2

    newLabel.transform = CGAffineTransformConCat(
      CGAffineTransformMakeScale(1,0)
      CGAffineTransformMakeTranslation(0,newLabelOffset)
    )

I've heard that the new way of using CGAffineTransformConCat is concatenating(_:) but not entirely sure how to set it up based on the 2 above transforms.

2 Answers

In swift, Function is overloadable. All matrix transform which contains translation, scale, rotate implemented by function CGAffineTransform() using different parameters.

init(rotationAngle: CGFloat)  // rotate
init(scaleX: CGFloat, y: CGFloat) // scale
init(translationX: CGFloat, y: CGFloat) // translation
func concatenating(CGAffineTransform) -> CGAffineTransform // matrix multiplication

Even, you can totally define transform matrix by using init(a: CGFloat, b: CGFloat, c: CGFloat, d: CGFloat, tx: CGFloat, ty: CGFloat), the construct of matrix is:

enter image description here

More: Apple developer documentation of CGAffineTransform

Related