平滑和加速 ProgressView
Smooth and Accelerating ProgressView
我正在玩 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
}
,我实现了每秒移动一次,但是怎么让它走的很顺,开始慢,加速,好看
使用 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.
}
}
我正在玩 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
}
使用 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.
}
}