Having examined some of the similar questions (Change uiview size after rotation transform and How to resize the UIView when CGAffineTransformIdentity) and read the Official documentation about CGAffineTransform I have come to some simple conclusions. Will explain them below.
When you use CGAffineTransform
for some object with followed frame transform you must use some rules for obtain correct result:
If transform property of object is equal CGAffineTransformIdentity
you can change frame of object or use CGAffineTransform
without restriction.
If If transform property of object is not equal CGAffineTransformIdentity
and you want change frame of object without CGAffineTransform
:
a) save value of object transform to some local (or another type) variable
b) set transform property of object to CGAffineTransformIdentity
c) change frame of object
d) restore transform value from local (or another type) variable.
- If transform property of object is not equal
CGAffineTransformIdentity
and you want use CGAffineTransform
, for example new_transform
:
a) use CGAffineTransformConcat([object transform] , new_transform)
to obtain result_transform
b) set transform value of object to result_transform
Compliance with these simple rules will help avoid many problems.
Note: you must remember, when you use CGAffineTransformConcat
all transform totalized. For example: if you want rotate object from 6 degree to 7 degree, you must add transform rotate to 1 degree, not to 7. Otherwise you obtain rotation 6 + 7 = 13 degree.