Md1079
Md1079

Reputation: 1360

CGAffineTransform not scaling origin correctly

I may be misunderstanding how the CGAffineTransform works but it seems to be giving strange results for the origin of the frame.

for example :

        print(attribute.frame)
        attribute.transform = CGAffineTransform(scaleX: 0.68, y: 0.68)
        print(attribute.frame)

gives the results :

(213.0, 54.0, 459.0, 23.5)

(286.29948979591836, 57.75280612244898, 312.4010204081633, 15.994387755102032)

The width and height scale correctly but the x and y origin have increased in value.

Upvotes: 0

Views: 736

Answers (2)

SveinnV
SveinnV

Reputation: 184

The transform uses the center of your view as anchor point. The result being that the center stays the same, should be (442.5, 65,75) if i calculate correctly but the origin will move (increase in value if you scale down, and decrease if you scale up). There are various techniques to change the anchor point if you want to keep the origin, perhaps take a look at this thread : Scale with CGAffineTransform and set the anchor

Upvotes: 2

Frank Cheng
Frank Cheng

Reputation: 6186

I thinks the transform must be apply to the center of rect.
I don't know what is the type of attribute. Maybe there is something called anchor inside attribute. You can try to change the property.

Upvotes: 1

Related Questions