围绕一个点旋转UIView / UITableView

时间:2012-02-01 20:16:27

标签: iphone animation rotation

我尝试围绕一个点旋转UITableView,我使用这个仅适用于一半的IBAction

CALayer *l = self.table.layer;
l.anchorPoint = CGPointMake(0,0);
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:1];
[UIView setAnimationCurve:UIViewAnimationCurveEaseIn];
CGAffineTransform rotate = CGAffineTransformMakeRotation(0.6);
table.transform = rotate;
[UIView commitAnimations];

当我点击按钮时,所有桌子的第一个移动到另一个位置而不是围绕一个角旋转......问题是桌子在动画开始时移动到另一个位置。如果我放

    CALayer *l = self.table.layer;
l.anchorPoint = CGPointMake(0,0);

在viewdidload上打开应用程序时,tableview是另一个位置,但动画是正确的,似乎l.anchorPoint将表移动到另一个位置......错误在哪里?

1 个答案:

答案 0 :(得分:2)

问题可能出在l.anchor

setAnchor方法设置图层中centreframe。您已将中心点设置在左上角(0,0)。 (1,1)将是右下角。

图层通过使用centre属性来定位自身。这表示超级层中的坐标。因为您更改了锚点,所以您的图层将被偏移,因为中心属性现在是从左上角开始引用,但具有相同的子图层坐标。

如果您将锚点设置为(1,1),您会发现右下角现在位于左上角的位置。

要解决您的问题,请设置定位点并通过设置centre属性重新定位图层。

l.center = CGPoint (l.center.x - (l.frame.size.width/2), l.center.y - (l.frame.size.height/2);

上面的代码可以解决问题。

相关问题