I am moving a view upward to some offset multiple times. My code is here:
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)")
}
}
}
The problem is that "animation completed" is printing after outer loop completes (after 10 times), not just after that particular animation gets completed. Means , when below code get executed after 10 times
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)")
}
}
then all completion block executes