我将视图向上移动到多次偏移。我的代码在这里:
for i in 0..<10 {
UIView.animate(withDuration: TimeInterval(duration), animations: {
view.frame = CGRect(x: view.frame.origin.x, y: view.frame.origin.y - offset, width: view.frame.size.width, height: view.frame.size.height)
}) { (boolValue) in
DispatchQueue.main.async {
print("loop completed -- \(i)")
}
}
}
问题是“动画完成”是在外循环完成后(10次之后)打印,而不仅仅是在特定动画完成之后。 意味着,当下面的代码执行10次后
UIView.animate(withDuration: TimeInterval(duration), animations: {
view.frame = CGRect(x: view.frame.origin.x, y: view.frame.origin.y - offset, width: view.frame.size.width, height: view.frame.size.height)
}) { (boolValue) in
DispatchQueue.main.async {
print("loop completed -- \(i)")
}
}
然后所有完成块执行