I am trying to do a little animation which change a label frame along with changing the font size. I have seen that animating directly the font size is not possible. So I have tried to use CGAffineTransform.
Here is what I have tried so far :
UIView.animateWithDuration(1, animations: {
if self.topConstraint.active {
self.initialTopConstraint.active = false
self.initialLeadingConstraint.active = false
self.label.transform = CGAffineTransformMakeScale(0.5, 0.5)
self.finalTopConstraint.active = true
self.finalLeadingConstraint.active = true
}
else {
self.initialTopConstraint.active = true
self.initialLeftConstraint.active = true
self.label.transform = CGAffineTransformMakeScale(1.5, 1.5)
self.finalTopConstraint.active = false
self.finalLeftConstraint.active = false
}
self.view.layoutIfNeeded()
})
In fact, this works, but I am using auto layout, and at the end of the animation, the constraints are not satisfied at all. The final constraints constants are 8, and when I print the label frame at the end of the animation, the label is around 13 points from the left and around 16 points from the top.
Initial frame :
Final frame with constraints respected but no font size changes made :
Final frame with constraints not respected and font size changes made :
Is there anyway to combine properly Auto layout and CGAffineTransform ?