Ios 如何设置要填充的圆的动画,而不是使用.trim?
我在下面有一个环形样式视图,这个动画从一个100%填充的环形开始,“取消填充”到修剪量,我想反转动画,使它从0开始,填充到修剪量Ios 如何设置要填充的圆的动画,而不是使用.trim?,ios,swift,animation,swiftui,Ios,Swift,Animation,Swiftui,我在下面有一个环形样式视图,这个动画从一个100%填充的环形开始,“取消填充”到修剪量,我想反转动画,使它从0开始,填充到修剪量 var progressAnimation: Animation { Animation .linear .speed(0.5) .delay(0.2) } var body: some View { VStack {
var progressAnimation: Animation {
Animation
.linear
.speed(0.5)
.delay(0.2)
}
var body: some View {
VStack {
ZStack {
Circle()
.stroke(Color(.systemFill).opacity(0.5), style: StrokeStyle(lineWidth: lineWidth))
.frame(height: 125)
Circle()
.trim(from: CGFloat(getTrimLevelForRingFromExertionLevel()), to: 1)
.stroke(ColorManager.getColorsForMetric(metricType: .Exertion(value: mostRecentEffortLevelObject?.effortLevel ?? 0)),
style: StrokeStyle(lineWidth: lineWidth, lineCap: .round, lineJoin: .round, miterLimit: .infinity, dash: [20, 0], dashPhase: 0))
.animation(self.progressAnimation, value: getTrimLevelForRingFromExertionLevel())
.rotationEffect(Angle(degrees: 90))
.rotation3DEffect(Angle(degrees: 180), axis: (x: 1, y: 0, z: 0))
.frame(height: 125)
可能您在不同的代码或模型中遇到了问题,因为引用答案中的方法工作得很好 这是一个完整的演示。使用Xcode 12.4/iOS 14.4进行测试
这回答了你的问题吗?这是我在上一个问题中遇到的另一个问题,是的,效果很好!但在我这里的问题中:我们正在构建一个圆,然后对其进行修剪,但是我想将修剪从0设置为修剪,而不是从100%设置为修剪。对不起,我以为您只是指答案中的一行,而不是另一个问题中的全部代码。很好用!
struct DemoView: View {
@State private var progress = 0.0
var body: some View {
VStack {
Circle()
.trim(from: 0.0, to: CGFloat(min(self.progress, 1.0)))
.stroke(Color.blue ,style: StrokeStyle(lineWidth: 25.0, lineCap: .round, lineJoin: .round))
.animation(.linear, value: progress)
.rotationEffect(Angle(degrees: 270.0))
.onAppear {
DispatchQueue.main.asyncAfter(deadline: .now() + 2) {
progress = 0.73
}
}
}.padding()
}
}