I've been using CGAffineTransformMakeScale to scale a UIView. This scales it by it's default anchorPoint, which is (.5, .5) -- the center. I'd like to scale it so that it stretches towards the left, as if it were zooming towards the left. I can accomplish this by setting the anchorPoint to the right center. However, this causes problems with setting the frame, etc. Is there a better way to apply a scale transform like I want. I was thinking I could do it with a custom transform matrix, but I am no good with matrix math.
2 Answers
3
votes
1
votes
First run this code and you will have better understanding. Here lblLabel is my label, you can change accordingly. Also check CGPoint(x: 10, y: 98) and CGPoint(x: 10, y: 108) as par > your requirements. This will animate from Top Left corner of label. Change anchor point and position as par your requirements.
self.lblLabel.layer.anchorPoint = CGPoint(x: 0.0,y :0.0)
self.lblLabel.layer.position = CGPoint(x: 10, y: 98)
lblLabel.transform = CGAffineTransform(scaleX: 0.5, y: 0.5)
UIView.animate(withDuration: 1.0) {
self.lblLabel.layer.position = CGPoint(x: 10, y: 108)
self.lblLabel.transform = CGAffineTransform(scaleX: 1.2, y: 1.2)
}