使用Swift5.5、iOS15.0.1、
我不得不意识到我的圆形 ProgressBar 在更新到 iOS15 后不再动画。
下面是我的代码 - 谁能告诉我该怎么做才能使圆形 ProgressBar-View 再次动画?
谁能告诉我如何在这个例子中规避弃用警告
animation' was deprecated in iOS 15.0: Use withAnimation or animation(_:value:) instead.
?
import SwiftUI
struct ContentView: View {
@State var progressValue: Float = 0.28
var body: some View {
ProgressBar(progress: $progressValue)
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}
struct ProgressBar: View {
@Binding var progress: Float
var body: some View {
ZStack {
Circle()
.stroke(lineWidth: 20.0)
.opacity(0.3)
.foregroundColor(Color.red)
Circle()
.trim(from: 0.0, to: CGFloat(min(self.progress, 1.0)))
.stroke(style: StrokeStyle(lineWidth: 20.0, lineCap: .round, lineJoin: .round))
.foregroundColor(Color.red)
.rotationEffect(Angle(degrees: 270.0))
.animation(.linear)
Text(String(format: "%.0f %%", min(self.progress, 1.0)*100.0))
.font(.largeTitle)
.bold()
}
}
}
我的原始版本如下所示:
Circle()
.trim(from: 0, to: showFreespaceRing ? CGFloat(Double(freeDiskspace) / Double(totalDiskspace)) : 0)
.stroke(Color.green.opacity(0.7), style: StrokeStyle(lineWidth: 10, lineCap: .round))
.frame(width: circleDiam, height: circleDiam)
.animation(.easeIn(duration: 1))
.onAppear() {
showFreespaceRing = true
}