Scale UIView without scaling subviews

2019-04-25 08:48发布

I'm trying to scale an UIView without scaling its subviews, or in my case I just want the subviews to be scaled in one axis. I need these hierarchy because I'm setting some Gesture Recognizers to detect panning and rotation and I want these to happen simultaneously with the parent view.

However, I don't want the scaling to happen simultaneously. For some subviews I want it to happen only vertically or horizontally or no scaling at all.

Is there a way to control the auto-scaling in an UIView's subviews when using CGAffineTransform on the UIView?

2条回答
太酷不给撩
2楼-- · 2019-04-25 09:03

Set the view's autoresizesSubviews to NO, by default it's YES.

查看更多
爱情/是我丢掉的垃圾
3楼-- · 2019-04-25 09:17

If you ensure the autoresizingMask's of subviews is correctly set up, you can change the frame of the container UIView (it is animatable) and the subviews will not change size (if your resizing mask is correct). Turning off containerView.autoresizesSubviews and changing the frame should also work.

查看更多
登录 后发表回答