1

我想对一些包含 UIImageView 的 UIView 执行 catransform3dmakerotation ,以使其看起来像在旋转。它可以工作,但是在我缩放 UIView(并因此拉伸其中的图像)之后,锚点是错误的(不再位于图形的中心)。

如何重置锚点?我的意思是真的重置它。因为我试过这个:

[self.view viewWithTag:100].layer.anchorPoint = CGPointMake(0.5, 0.5);

每次加速度计值改变时,在重新缩放后几乎每 0.1 秒更新一次,图像正在旋转但不再居中,它似乎在其原点 (0,0) 上旋转,而不是 (0.5,0.5 ),尽管它应该在加速度计中更新:didAccelerate:方法。但它没有用。这是重新缩放的代码:

UIView* buttView = (UIView*) [self.view viewWithTag:101];
UIImageView* butt = (UIImageView*)[self.view viewWithTag:100];
butt.frame= CGRectMake(butt.frame.origin.x, butt.frame.origin.x, newSize, newSize);
buttView.frame = butt.frame;

谢谢!

4

1 回答 1

2

在更改之前,anchorPoint您需要记住旧框架并在更改后重置它。像这样:

CGRect oldFrame = [[self.view viewWithTag:100] frame];
[self.view viewWithTag:100].layer.anchorPoint = CGPointMake(0.5, 0.5);
[[self.view viewWithTag:100] setFrame:oldFrame];
于 2011-06-19T13:01:05.853 回答