Reputation: 5441
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.
Upvotes: 4
Views: 5301
Reputation: 89
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:
More: Apple developer documentation of CGAffineTransform
Upvotes: 0
Reputation: 1814
Init transforms,
let trans1 = CGAffineTransform(scaleX: 0, y: 0)
let trans2 = CGAffineTransform(translationX: 0,y: 1)
Concatenate,
trans1.concatenating(trans2)
Upvotes: 13