【发布时间】:2020-11-20 12:46:50
【问题描述】:
我有 6 个视图。我想一个一个地为约束设置动画,即,我只需要在第二个视图上的动画在第一个之后,然后在第二个第三个之后,依此类推。我已经在动画的完成处理程序中添加了代码,但它不起作用。所有约束的初始值在情节提要中设置为 300。我想把它一个一个改成0。现在,只有第一个动画在起作用。这就是我所做的。
layoutTopFirst.constant = 0.0;
[UIView animateWithDuration:1.0 animations:^{
[self.view layoutIfNeeded];
} completion:^(BOOL finished) {
self->layoutTopSecond.constant = 0.0;
[UIView animateWithDuration:1.0 animations:^{
[self.view layoutIfNeeded];
} completion:^(BOOL finished) {
self->layoutTopThird.constant = 0.0;
[UIView animateWithDuration:1.0 animations:^{
[self.view layoutIfNeeded];
} completion:^(BOOL finished) {
self->layoutTopFourth.constant = 0.0;
[UIView animateWithDuration:1.0 animations:^{
[self.view layoutIfNeeded];
} completion:^(BOOL finished) {
self->layoutTopFifth.constant = 0.0;
[UIView animateWithDuration:1.0 animations:^{
[self.view layoutIfNeeded];
} completion:^(BOOL finished) {
self->layoutTopSixth.constant = 0.0;
[UIView animateWithDuration:1.0 animations:^{
[self.view layoutIfNeeded];
} completion:^(BOOL finished) {
}];
}];
}];
}];
}];
}];
如何一个接一个的做动画?
【问题讨论】:
-
“它不工作”以什么方式?一次全部制作动画吗?没有动画吗?只有第一个动画吗?请详细说明。
-
@Stonz2 我已经更新了这个问题。现在只有第一个动画了
-
你能在每次完成时添加一个日志来看看发生了什么吗?请注意,这不完全是 Swift 主题,但没关系。
标签: ios objective-c swift nslayoutconstraint uiviewanimationtransition