user2489946
user2489946

Reputation: 291

Subviews Misplaced after superview is scaled via CGAffineTransform

I am trying to Scale a UiView and its UIImageView subview using: CGAffineTransform original = mv.transform; CGAffineTransform new = CGAffineTransformScale(original, 2, 2);

But this results in the ImageView being way off from where it started:

Before the transofrm the imageview (the book) is at the center of the purple circle. This shows it after the transform(which is done in a spring animation block)

Before the transofrm the imageview (the book) is at the center of the purple circle. This shows it after the transform(which is done in a spring animation block)

For the record autolayout is off in IB

Upvotes: 0

Views: 977

Answers (1)

user2489946
user2489946

Reputation: 291

So after tinkering with it for some hours, I was able produce the desired effect. I was also changing the center of the view in the animation block and I found that if I placed the statement assigning the center value before assigned the new transfrom, the subview stayed centered during the transform and center - change. Also, I found that if I was working with a UIView subclass, I had to make a call to layoutIfNeeded before the animation block on the view being scaled and moved. Interestingly enough, when working with regular UIView objects I found that it was not necessary to make the call to layoutIfNeeded in order to produce the desired effect of keeping the subview centered after the center cahnge and transform.

I am at a loss as to why these specific conditions are required to keep the subview centered during a transform and coordinate move. I've been looking through the Apple Documentation but have yet to find a sure explanation.

Upvotes: 1

Related Questions