Iphone 围绕点旋转UIView/UITableView
我试着围绕一个点旋转一个UITableView,我使用的这个iAction只能工作一半Iphone 围绕点旋转UIView/UITableView,iphone,animation,rotation,Iphone,Animation,Rotation,我试着围绕一个点旋转一个UITableView,我使用的这个iAction只能工作一半 CALayer *l = self.table.layer; l.anchorPoint = CGPointMake(0,0); [UIView beginAnimations:nil context:NULL]; [UIView setAnimationDuration:1]; [UIView setAnimationCurve:UIViewAnimationCurveEaseIn]; CGAffineTr
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将表格移动到另一个位置…错误在哪里?问题可能是与
l.anchor
有关
setAnchor
方法设置层中帧的中心点。您已将中心点设置在左上角(0,0)。(1,1)将是右下角
该层通过使用中心
属性来定位自身。这表示超级层中的坐标。由于更改了定位点,图层将偏移,因为现在正从左上角引用中心特性,但具有相同的子图层坐标
如果将锚点设置为(1,1),您会注意到右下角现在位于左上角的位置
要解决您的问题,请通过设置center
属性设置锚定点并重新定位图层
l.center = CGPoint (l.center.x - (l.frame.size.width/2), l.center.y - (l.frame.size.height/2);
上面的代码应该可以做到这一点。对不起,如果我尝试使用您的代码,我会遇到以下错误:在“CALayer*”类型的对象上找不到属性“center”,我必须设置图层或视图的中心吗?