本文介绍了如何在缩放后将视图位置重置为原点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的应用程序中有两个视图,viewA(绿色)和subviewB(红色)。我的应用程序的初始状态如下:
There's two views in my app, viewA(green) and subviewB(red). The initial state of my app is as following:
我使用以下代码更改viewA的转换:
I use the following code to change the transform of viewA:
CGFloat scale = 0.4;
self.viewA.layer.sublayerTransform = CATransform3DMakeScale(scale, scale, 1);
因此,子视图B被缩放和翻译
as a result, the subviewB is scaled and translated
但是我的应用程序有一个问题:我需要subViewB仍然在viewA的左上角,但是subviewB看着移动到viewA的中心,这很奇怪,subviewB的原点仍然是(0,0),是什么我可以将subviewB移动到左上角吗?
but there's a problem for my app: I need the subViewB is still at the top-left corner in viewA, but subviewB is look at moved to center of viewA, it's weird that the origin point of subviewB is still (0,0), what can I do to move the subviewB to top-left corner?
推荐答案
只需尝试给出的代码,
subviewB.transform = CGAffineTransformScale(test.transform, scale, scale);
它会起作用:)
这篇关于如何在缩放后将视图位置重置为原点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!