我有一个简单的动画,可以移动我的视图层,并保持最终状态。
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";
为什么会这样?
答案 0 :(得分:0)
因为,当您更改文本时,视图需要重绘,
如果启用此视图的autoLayout(默认为启用),则会将帧调整为自动布局。
所以有解决方案
选项1: 禁用视图的自动布局
选项2 当谈到帧改变的动画时,尝试动画自动布局