我试图使用显式动画为position
的{{1}}和rotation
属性设置动画,结果是UIView
已成功更新但rotation
已成功更新虽然我在将动画添加到视图图层后立即将图层的position
和position
属性更新为其最终值,但视图的1}}确实更新了不更新猜它是所谓的显式覆盖隐式动画技术?)。
这是我的代码:
rotation
如果我单独实现位置或旋转动画,代码表现良好,我得到了预期的结果。但当它与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];
结合时,位置最终不会更新为最终值
这里有什么想法吗?
答案 0 :(得分:0)
也许试试这个:当然还有你的价值观:
[UIView animateWithDuration:1.0f animations:^{
self.square.center = CGPointMake(10, 10);
self.square.transform =CGAffineTransformMakeRotation(90);
}completion:nil];