我正在玩 ProgressView。我想要实现的是在按钮单击时停止在 33%、66%、100% 检查点。如果我使用 progressView.progress = 0.33
它工作正常,但它直接降落到检查点。相反,让它平稳和加速看起来会很好。
我认为 animateWithDuration
会起作用,但不幸的是它不起作用。阅读之后,我发现我可以使用 NSTimer 做一些事情,但我无法实现它。
var progressView: UIProgressView?
override func viewDidLoad()
{
super.viewDidLoad()
progressView = UIProgressView(progressViewStyle: UIProgressViewStyle.Default)
progressView?.center = self.view.center
progressView?.trackTintColor = UIColor.redColor()
progressView?.progressTintColor = UIColor.greenColor()
view.addSubview(progressView!)
progressView!.progress = 0.0
}
Using this answer ,我实现了让它每秒移动一次,但是我怎样才能使它平滑,开始缓慢并加速,所以看起来不错。
最佳答案
使用 setProgress 方法并将动画设置为 true 使动画工作。
import UIKit
class ViewController: UIViewController {
@IBOutlet weak var pb: UIProgressView!
@IBOutlet weak var btn: UIButton!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
pb.progress = 0.00
}
@IBAction func btnPress(sender: UIButton) {
UIView.animateWithDuration(3, animations: {
self.pb.setProgress((self.pb.progress + 0.33), animated: true)
}, completion: nil)
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
关于ios - 平稳加速进度View,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37095880/