开发者

How do I get a CGAffineTransformMakeScale to shrink a view around its center?

开发者 https://www.devze.com 2022-12-29 15:08 出处:网络
This should be an easy one -- when I u开发者_开发百科se a CGAffineTransformMakeScale on a UIView with width = 0.5 and height = 0.5, it shrinks to the upper left.I need it to shrink around its center.

This should be an easy one -- when I u开发者_开发百科se a CGAffineTransformMakeScale on a UIView with width = 0.5 and height = 0.5, it shrinks to the upper left. I need it to shrink around its center.

How can I achieve that?


Make sure to turn off Autolayout if you are experiencing the same behaviour!


Aha, figured this one out. I was doing some custom drawing and had mixed up frame and bounds.


By default CGAffineTransformMakeScale will scale UIViews around their center.

For example:

[UIView animateWithDuration:0.5 delay:0 options:UIViewAnimationCurveEaseInOut animations:^{
    self.myView.transform = CGAffineTransformMakeScale(2, 2);
}  completion:nil ]; 

.. will make the myView twice the size, scaled around its center.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号