Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multiple CGAffineTransforms in Swift 3

In Swift 2, we could do this to get a rotation and a stretch:

let rotate = CGAffineTransformMakeRotation(1) 
let stretchAndRotate = CGAffineTransformScale(rotate, 0.8, 0.8) 
label.transform = stretchAndRotate

In Swift 3, CGAffineTransformScale has become CGAffineTransform and no longer accepts a rotation.

What is the simplest way to apply a stretch and rotation to an object now?

Thanks,

Rob

like image 550
user2428168 Avatar asked Jul 07 '16 18:07

user2428168


1 Answers

In Swift 3 many global C functions are mapped to member functions of the corresponding type, compare "Import as member" on swift-evolution.

In your case it would be

let rotate = CGAffineTransform(rotationAngle: 1.0)
let stretchAndRotate = rotate.scaleBy(x: 0.8, y: 0.8)
like image 146
Martin R Avatar answered Nov 09 '22 09:11

Martin R