Swift CGAffineTransformScale to scale, not scale

Let's say I scale a UILabel using a CGAffineTransformScale, for example:

let scale = 0.5
text = UILabel(frame: CGRectMake(100, 100, 100, 100))
text.text = "Test"

UIView.animateWithDuration(2.0, delay: 0.0, options: UIViewAnimationOptions.CurveEaseIn, animations: {
    self.text.transform = CGAffineTransformScale(self.text.transform, scale, scale)
}, completion: {(value : Bool) in
    print("Animation finished")
})

This works great when I want to scale UILabel by half. But if I dialed the same code again, it would have got a scale of 0.25, since it scales again by half.

Is it possible to use CGAffineTransformScale to always scale to half the size of the original UILabel frame, rather than scale it cumulatively?

+4
source share
2 answers

Swift 3 :

text.transform = CGAffineTransform.identity
UIView.animate(withDuration: 0.25, animations: {
   self.text.transform = CGAffineTransform(scaleX: scale, y: scale)
})
+13
source

You scale the existing transformation. Just create a new transformation:

self.text.transform = CGAffineTransformMakeScale(scale, scale)
+5
source

All Articles