仅将 CGAffineTransform 的缩放组件应用于 UIView [英] Applying just the scale component of a CGAffineTransform to a UIView
问题描述
我有一个 UIView,它应用了各种缩放和旋转 CGAffineTransforms,以响应触摸屏手势.
当缩放操作完成时,我想将视图的边界调整到新的大小,然后让视图以 1.0 的比例重新绘制自己,同时保持变换的所有其他组件相同.>
要调整视图的边界,我正在使用:
self.myView.bounds = CGRectApplyAffineTransform(self.myView.bounds, self.myView.transform);
要撤消"缩放变换,我正在尝试:
self.myView.transform = CGAffineTransformConcat(self.myView.transform, CGAffineTransformMakeScale(1, 1));
然后调用 [myView setNeedsDisplay]
让视图重绘自身.
然而,这不会产生预期的结果,当应用旋转变换时,上面的代码似乎也导致应用了横向平移变换.
仅撤消"缩放变换并使视图以 1:1 重绘而所有其他变换保持不变的最简洁方法是什么?
将您的比例值保存在一个变量中,然后尝试将 CGAffineTransformMakeScale(1, 1) 更改为
CGAffineTransformMakeScale(1/totalScaleWidth, 1/totalScaleHeight)
I have a UIView to which various scale and rotation CGAffineTransforms have been applied, in response to touch screen gestures.
When a scale operation completes, I want to adjust the bounds of the view to the new size, then have view to re-draw itself at a scale of 1.0, while keeping all other components of the transform the same.
To adjust the bounds of the view, I'm using:
self.myView.bounds = CGRectApplyAffineTransform(self.myView.bounds, self.myView.transform);
To "undo" the scale transform, I'm trying this:
self.myView.transform = CGAffineTransformConcat(self.myView.transform, CGAffineTransformMakeScale(1, 1));
then calling [myView setNeedsDisplay]
to get the view to redraw itself.
However this does not produce the desired results and when a rotate transform is applied, the above code seems to cause what looks like a sideways translation transform to be applied too.
What's the cleanest way to "undo" just a scale transform and have the view redraw at 1:1 with all other transforms remaining intact?
Save your scale values in a variable and then, try changing CGAffineTransformMakeScale(1, 1) into
CGAffineTransformMakeScale(1/totalScaleWidth, 1/totalScaleHeight)
这篇关于仅将 CGAffineTransform 的缩放组件应用于 UIView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!