当我执行下面的代码时,遇到了一个奇怪的问题,这段代码是针对应用旋转变换的UIView编写的。我的目标是将该视图从其父视图中移除,然后将其插入到特定视图下方并恢复其框架:
UIView* movedView= [self.views objectAtIndex:newIndex];
center = movedView.center;
CGRect oldFrame = movedView.frame;
//find the layer on top and insert the moved view under that
UIView* coveringView = [self.views objectAtIndex:newIndex-1];
[movedView removeFromSuperview];
[self.view insertSubview:movedView belowSubview:coveringView];
movedView.frame = oldFrame;
我期望在操作后,视图应该出现在同一位置,但是它会根据通过CGAffineTransformMakeRotation()应用的旋转量而移动位置。
通过替换将frame赋值的调用为将center属性赋值的调用,我获得了期望的行为。这让我想到了一个问题 - 当UIView旋转时,我如何理解它的frame发生了什么变化?是否有好的教程或其他东西可以帮助我概念性地理解变换如何影响UIView的frame?