所以我有一个动画,从左到右移动一个视图,然后在.2秒后反弹。我为第二个视图启动相同的动画。问题是第一个动画中的layoutIfNeeded影响第二个动画,我没有得到0.2秒的延迟。有什么方法吗? (我想我可以通过添加他们自己的超级视图中的每一行并在其上运行layoutIfNeeded来解决它,但我希望将视图数量保持在最低限度) 所以这是我的代码:
[self removeConstraint:_thirdRowConstraint];
_thirdRowConstraint = [NSLayoutConstraint constraintWithItem:row3 attribute:NSLayoutAttributeCenterX relatedBy:NSLayoutRelationEqual toItem:self attribute:NSLayoutAttributeCenterX multiplier:1 constant:0];
[self addConstraint:_thirdRowConstraint];
[UIView animateWithDuration:0.2 delay: 0 options: 0 animations:^{
[self layoutIfNeeded];
} completion:^(BOOL finished) {
[self removeConstraint:_thirdRowConstraint];
_thirdRowConstraint = [NSLayoutConstraint constraintWithItem:row3 attribute:NSLayoutAttributeCenterX relatedBy:NSLayoutRelationEqual toItem:self attribute:NSLayoutAttributeCenterX multiplier:1 constant:20];
[self addConstraint:_thirdRowConstraint];
[UIView animateWithDuration:0.2 animations:^{
[self layoutIfNeeded];
} completion:^(BOOL finished) {
[self removeConstraint:_thirdRowConstraint];
_thirdRowConstraint = [NSLayoutConstraint constraintWithItem:row3 attribute:NSLayoutAttributeCenterX relatedBy:NSLayoutRelationEqual toItem:self attribute:NSLayoutAttributeCenterX multiplier:1 constant:0];
[self addConstraint:_thirdRowConstraint];
[UIView animateWithDuration:0.2 animations:^{
[self layoutIfNeeded];
}completion:^(BOOL finished) {
}];
}];
}];
[self removeConstraint:_forthRowConstraint];
_forthRowConstraint = [NSLayoutConstraint constraintWithItem:row4 attribute:NSLayoutAttributeCenterX relatedBy:NSLayoutRelationEqual toItem:self attribute:NSLayoutAttributeCenterX multiplier:1 constant:0];
[self addConstraint:_forthRowConstraint];
[UIView animateWithDuration:0.2 delay: 0.2 options: 0 animations:^{
[self layoutIfNeeded];
} completion:^(BOOL finished) {
[self removeConstraint:_forthRowConstraint];
_forthRowConstraint = [NSLayoutConstraint constraintWithItem:row4 attribute:NSLayoutAttributeCenterX relatedBy:NSLayoutRelationEqual toItem:self attribute:NSLayoutAttributeCenterX multiplier:1 constant:20];
[self addConstraint:_forthRowConstraint];
[UIView animateWithDuration:0.2 animations:^{
[self layoutIfNeeded];
} completion:^(BOOL finished) {
[self removeConstraint:_forthRowConstraint];
_forthRowConstraint = [NSLayoutConstraint constraintWithItem:row4 attribute:NSLayoutAttributeCenterX relatedBy:NSLayoutRelationEqual toItem:self attribute:NSLayoutAttributeCenterX multiplier:1 constant:0];
[self addConstraint:_forthRowConstraint];
[UIView animateWithDuration:0.2 animations:^{
[self layoutIfNeeded];
}completion:^(BOOL finished) {
}];
}];
}];