在使用 setFrame 重新绘制框架后,我的转换不绘制。
我在使用 setFrame 更改方向时缩放 View 。但此 View 还需要根据 BOOL
参数更改位置:On = 在 View 中向上,off = 在屏幕外向下。我使用 setTransform
来调整 View 的位置。
首先,我通过执行 setFrame
来绘制 View 。这会在屏幕底部绘制 View 100 点。然后我设置一个转换(-100 在 ty 上)将它带到视点(只要 BOOL
设置为 TRUE
,否则转换为 0并且 View 在屏幕外)。
[view setFrame:CGRectMake(0, self.view.bounds.size.height, self.view.bounds.size.width, 100)];
[view setTransform:CGAffineTransformMake(1, 0, 0, 1, 0, -100)]
正如预期的那样,这工作正常,但是当改变方向并且重新运行此代码(以重新调整 View 大小)时,变换不会绘制,即使它被记录为 View 的变换。换句话说, View 就在屏幕外,就好像 transform.ty 为 0。
Log message before re-draw: view.transform.ty -10.000000
Log message after re-draw: view.transform.ty -10.000000
有什么帮助吗?
最佳答案
View 的frame
是从三个基本值派生的值:bounds
、center
和转换
。 frame
的 setter 试图通过反转过程来做正确的事情,但是当设置了非身份 transform
时它不能总是正确工作。
documentation在这一点上很清楚:
If the transform property is not the identity transform, the value of this property is undefined and therefore should be ignored.
...
If the transform property contains a non-identity transform, the value of the frame property is undefined and should not be modified. In that case, you can reposition the view using the center property and adjust the size using the bounds property instead.
由于您的transform
仅转换 View ,所以我看不出有任何理由使用它。只需更改 View 框架的原点:
[view setFrame:CGRectMake(0, self.view.bounds.size.height - 100, self.view.bounds.size.width, 100)];
关于iOS,setTransform 被 setFrame 覆盖了吗?重新运行 setFrame 后不重新绘制变换,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14180542/