【发布时间】:2020-08-15 10:34:33
【问题描述】:
可以在 SwiftUI 中将日期传递给 Text(),然后使用 style 参数将其格式化为计时器。然而,像这样的倒计时永远不会停止,它只是在零之后不断增加。如何让它停在0?
func nextRollTime(in seconds: Int) -> Date {
let date = Calendar.current.date(byAdding: .second, value: seconds, to: Date())
return date ?? Date()
}
上面是我用来开始倒计时的函数,然后我传递如下:
Text(nextRollTime(in: 20), style: .timer)
【问题讨论】: