如何使用淡入淡出在一个标签中显示多个值



我想在一个标签中显示多个引号。当一个报价淡出,然后另一个报价淡入。我这样做-:

for i in self.splashModel?.quotations ?? [] {
self.quoteLabel.alpha = 0
print("CheckQuotes(i)")
Timer.scheduledTimer(withTimeInterval: 0.2, repeats: true, block: { timer in
self.quoteLabel.text = i
self.quoteLabel.fadeIn(completion: {
(finished: Bool) -> Void in
self.quoteLabel.fadeOut()
})
})

}

这只显示阵列的最后一项

试试这个-:

self.splashModel?.quotations.enumerated().forEach { (index,item) in
DispatchQueue.main.asyncAfter(deadline: .now() + Double( index * 2) ) {
self.quoteLabel.alpha = 0
self.quoteLabel.text = item
self.quoteLabel.fadeIn(completion: {(finished: Bool) -> Void in
self.quoteLabel.fadeOut()
})
} 

}

最新更新