[英]UIView Animation Chaining Doesn't Work Properly
我正在嘗試制作一個簡單的“ 加載”標簽文本的動畫,以在其后顯示3個點,每個點都有一秒鍾的延遲。
這是我嘗試過的:
func animateLoading() {
UIView.animate(withDuration: 1, animations: {self.yukleniyorLabel.text = "Yükleniyor."}, completion: { _ in
UIView.animate(withDuration: 1, animations: {self.yukleniyorLabel.text = "Yükleniyor.."}, completion: { _ in
UIView.animate(withDuration: 1, animations: {self.yukleniyorLabel.text = "Yükleniyor..."})
})
})
}
但是我得到的是所有3個點一起出現在1秒內。 順序不對。 看到這里: https : //streamable.com/yiz6s
鏈接發生了什么問題? 提前致謝。
UIView animate
僅適用於可動畫顯示的視圖屬性,例如框架和背景色。 self.yukleniyorLabel.text
不是可設置動畫的屬性。 所以你沒有動畫。
只需使用計時器或延遲的性能即可按時間間隔更改文本。
您可以使用預定的計時器在帶有動畫的標簽上顯示帶有三個點的文本:->
var i = 0
var timer : Timer?
loaderLabel.text = "Loading"
timer = Timer.scheduledTimer(timeInterval: 0.2, target: self, selector:#selector(ViewController.setText), userInfo: nil, repeats: true)
@objc func setText() {
loaderLabel.text = loaderLabel.text! + "."
i += 1
if i >= 3 {
timer?.invalidate()
}
}
動畫輸出:->正在加載...
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.