我正在尝试使用计时器并用颜色填充屏幕。简单地说:我用\(UIScreen.main.bounds.height)得到屏幕高度,然后用selectedTime划分它,比如说\(120)秒。问题出现在这里:屏幕填满了 232,而不是 844.0 屏幕尺寸,它在 32 秒而不是 120 秒内填满。我可能错过了一些东西。相关代码部分:
.onChange(of: secondsToMinutesAndSeconds(seconds: timerManager.secondsLeft), perform: { waveTime in
let selectedCircularValue = availableMinutes[self.selectedCircularIndex] * 60
let heightProgress = CGFloat(UIScreen.main.bounds.height / CGFloat(selectedCircularValue))
if timerManager.screenHeightChanged < UIScreen.main.bounds.height {
timerManager.screenHeightChanged += CGFloat(heightProgress)
withAnimation(.linear) {
self.colorSize = CGFloat(Double(timerManager.screenHeightChanged))
}
} else {
timerManager.screenHeightChanged = 0
}
})
进度输出
{ seconds 120
screenHeight 844.0
estimatedTime screen / seconds -> (7.033333333333333)
...
progress 14.066666666666666
...
progress 225.06666666666663
...
progress 232.09999999999997
}
最后,是否可以使动画流畅?