开发者社区> 问答> 正文

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"];

展开
收起
a123456678 2016-07-27 15:09:11 2070 0
1 条回答
写回答
取消 提交回答
  • 你需要弄清楚position和anchorPoint的关系, position其实就是anchorPoint在父layer中的坐标, 如果你改动了anchorPoint, positon的值不会变, 但是实际的位置会变。你可以把最后一句动画的代码去掉就会发现设置anchorPoint的时候button的位置就浮动了。你需要重新计算下改变anchorPoint之后的postion, 设置好, 然后再开始动画。

    2019-07-17 20:00:38
    赞同 展开评论 打赏
问答地址:
问答排行榜
最热
最新

相关电子书

更多
低代码开发师(初级)实战教程 立即下载
冬季实战营第三期:MySQL数据库进阶实战 立即下载
阿里巴巴DevOps 最佳实践手册 立即下载