0
我有一个简单的动画,它移动了我的视图的图层并保持它的最终状态。当标签的文字改变时,核心动画将图层返回到原始位置
CGPoint originalPosition = self.redSquare.layer.position;
self.redSquare.layer.position = CGPointMake(100, 100);
CABasicAnimation *animation = [[CABasicAnimation alloc]init];
animation.keyPath = @"position.x";
animation.fromValue = @(originalPosition.x);
animation.toValue = @250;
animation.duration = 2;
[self.redSquare.layer addAnimation:animation forKey:@"basic"];
self.redSquare.layer.position = CGPointMake(250, originalPosition.y);
但是,当我更改标签的文本时,图层跳转到它的原始位置。
CGPoint originalPosition = self.redSquare.layer.position;
self.redSquare.layer.position = CGPointMake(100, 100);
CABasicAnimation *animation = [[CABasicAnimation alloc]init];
animation.keyPath = @"position.x";
animation.fromValue = @(originalPosition.x);
animation.toValue = @250;
animation.duration = 2;
animation.delegate = self;
[self.redSquare.layer addAnimation:animation forKey:@"basic"];
self.redSquare.layer.position = CGPointMake(250, originalPosition.y);
self.label.text = @"Started";
为什么会发生?