IOS UIAnimation中的不寻常行为

时间:2018-05-18 05:56:24

标签: ios swift uiviewanimation

我将视图向上移动到多次偏移。我的代码在这里:

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)")
    }
}

然后所有完成块执行

0 个答案:

没有答案