简体   繁体   中英

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); CGAffineTransform original = mv.transform; CGAffineTransform new = CGAffineTransformScale(original, 2, 2);

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

在穿透之前,图像视图(书本)位于紫色圆圈的中心。转换后显示它(在spring动画块中完成)

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM