ios - 在CAAnimationGroup中设置位置和旋转的动画使位置在结束时不被更新

  显示原文与译文双语对照的内容
0 0

UIViewpositionrotation 属性的基础上,我尝试在图层中更新图层和 rotation 属性,但结果是 rotation 已经成功更新,但视图的position

这是我的代码:


CABasicAnimation *move = [CABasicAnimation animationWithKeyPath:@"position.y"];
move.fromValue = @(self.square.center.y);
move.toValue = @(300);

CABasicAnimation *rotate = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
rotate.fromValue = @(DEGREES_TO_RADIANS(0));
rotate.toValue = @(DEGREES_TO_RADIANS(45));

CAAnimationGroup *group = [CAAnimationGroup animation];
group.duration = 1.0;
group.animations = @[move, rotate];

self.square.center = CGPointMake(self.square.center.x, 300);
self.square.transform = CGAffineTransformMakeRotation(M_PI/4);
[self.square.layer addAnimation:group forKey:nil]; 

如果我单独实现位置或者旋转动画,代码表现良好,得到了预期结果。 但是当它合并到 CAAnimationGroup 中时,位置就不会更新到最后的最终值。
这里有什么想法?

时间: 原作者:

0 0

可以尝试:当然,使用你的值:


[UIView animateWithDuration:1.0f animations:^{
 self.square.center = CGPointMake(10, 10);
 self.square.transform =CGAffineTransformMakeRotation(90);
 }completion:nil];

...