首页 > CABasicAnimation旋转view,设置anchorPoint的,view会向上浮动一段距离再旋转。

CABasicAnimation旋转view,设置anchorPoint的,view会向上浮动一段距离再旋转。

CABasicAnimation旋转view,设置anchorPoint的,view会向上浮动一段距离再旋转。 请问向上浮动是为什么出现,怎么消除?
CABasicAnimation*rotationAnimation = [CABasicAnimation animationWithKeyPath:@"transform.rotation"];
rotationAnimation.toValue = [NSNumber numberWithFloat: M_PI * -0.3 ];
[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
rotationAnimation.duration = 0.3;
rotationAnimation.RepeatCount = 0;
rotationAnimation.cumulative = NO;
rotationAnimation.removedOnCompletion = NO;
rotationAnimation.fillMode = kCAFillModeForwards;

button.layer.anchorPoint=CGPointMake(0.5,1);
[button.layer addAnimation:rotationAnimation forKey:@"Rotation"];

你需要弄清楚position和anchorPoint的关系, position其实就是anchorPoint在父layer中的坐标, 如果你改动了anchorPoint, positon的值不会变, 但是实际的位置会变。你可以把最后一句动画的代码去掉就会发现设置anchorPoint的时候button的位置就浮动了。你需要重新计算下改变anchorPoint之后的postion, 设置好, 然后再开始动画。比如这样:搬运工

【热门文章】
【热门文章】