是否可以将转换标识设置为当前转换状态?我关心的是使用自动布局,一旦应用了转换,框架现在是未定义的。这只是一个抽象的思维过程,实际上可能不是问题。

假设我应用 CGAffineTransformMakeScale(1,-1) 来翻转作为某个 superView 的 subview 的 UIView。现在我已经对 subView 应用了一个转换,frame: now 变得未定义,那么如果我调整 superView 的大小,这将如何影响 subView 在 superView 中的大小和位置?

我的思考过程告诉我,如果我可以将“CGAffineTransformIdentity”设置为当前转换状态(例如在翻转或旋转之后),我设置的任何自动布局都将得到正确处理,但如果未设置,我将不会得到适当的处理自动布局处理。

那么我需要担心框架:未定义还是自动布局会使用转换 View 的边界:?

最佳答案

好问题。你是对的 frame of a UIView becomes undefined after applying a transform that is not equal to CGAffineTransformIdentity :



但是,您可能不知道 Auto Layout does not actually use the frame of a view to align it, but instead uses the "alignment rect" of the view 。使用 alignmentRectForFrame: 检索 View 的对齐矩形。

文档指出



并详细说



所以,为了回答你的问题,



答案是,在一般情况下,您必须实现 alignmentRectForFrame:frameForAlignmentRect: ,并确保它们彼此相反。

This is a more thorough treatment of the issue ,我建议你看看。

关于objective-c - CGAffineTransformIdentity 和自动布局,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/24964531/

10-13 08:31