gpt4 book ai didi

ios - Swift Progress View 动画使进度条超过 100%

转载 作者:行者123 更新时间:2023-11-28 09:52:28 26 4
gpt4 key购买 nike

当为 ProgressView 使用动画时,如果我让动画用完它会完全正常工作,但如果我尝试在动画仍在运行时再次运行此代码,它会将 100% 添加到当前栏并继续运行通过酒吧。图片应该以更合乎逻辑的方式解释情况。

进度从 1.0 (100%) 开始:

enter image description here

进度进行到一半:

Progress is half-way through

代码再次运行,导致进度超过 100%,尽管它使用了正确的时间来完成。

The code was ran again, resulting in the progress going above 100%, although it uses the correct amount of time to finish.

这里是使用的代码:

self.progressView.setProgress(1.0, animated: false)

DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) {
UIView.animate(withDuration: 10, delay: 0, options: [.beginFromCurrentState, .allowUserInteraction], animations: { [unowned self] in
self.progressView.setProgress(0, animated: true)
})
}

提前致谢!

最佳答案

一些快速研究...

原来 UIProgressView 需要一点特别的努力来停止当前的动画。看看这是否适合您:

    // stop any current animation
self.progressView.layer.sublayers?.forEach { $0.removeAllAnimations() }

// reset progressView to 100%
self.progressView.setProgress(1.0, animated: false)

DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) {
// set progressView to 0%, with animated set to false
self.progressView.setProgress(0.0, animated: false)
// 10-second animation changing from 100% to 0%
UIView.animate(withDuration: 10, delay: 0, options: [], animations: { [unowned self] in
self.progressView.layoutIfNeeded()
})
}

关于ios - Swift Progress View 动画使进度条超过 100%,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44397720/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com