我想使用带有缓动函数(例如 easeInOutQuad)的 CoreAnimation 将 UILabel.text 值从 0 增加到 100。但似乎文本属性不可设置动画。那么如何借助CA来实现呢?或者我需要自己实现缓动函数并使用 GCD 调用它吗? 谢谢
附言我想尽可能坚持 CA。
最佳答案
class ViewController: UIViewController {
@IBOutlet weak var label: UILabel!
var counter = 0
override func viewDidLoad() {
super.viewDidLoad()
let timer = NSTimer.scheduledTimerWithTimeInterval(1.0, target: self, selector: Selector("animate"), userInfo: nil, repeats: true)
timer.fire()
}
func animate() {
UIView.transitionWithView(label,
duration: 1.0,
options: [.CurveEaseInOut],
animations: { () -> Void in
self.counter += 1
self.label.text = "\(self.counter)"
}, completion: nil)
}
}
关于ios - 如何在 Swift 中使用 CoreAnimation 为 UILabel 文本属性设置动画?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36543897/