Page 1 of 1

Schlange wie Gradientengrenzanimation in iOS

Posted: 03 Jun 2025, 11:26
by Anonymous
Ich versuche, Schlangenbetriebs -Randanimation mit Gradientenfarbe anzusehen, siehe das Bild unten. Es kommt als Hintergrundansicht nicht als Rand. Unten ist der Swiftui -Code, den ich verwendet habe: < /p>

Code: Select all

struct GradientBorderAnimationView: View {
@State var rotation:CGFloat = 0.0

@State var width: CGFloat = 330
@State var height: CGFloat = 100

var body: some View {
ZStack{
RoundedRectangle(cornerRadius: 20, style: .continuous)
.frame(width: width*2, height: height*2)
.foregroundStyle(LinearGradient(gradient: Gradient(colors: [.white, .white, .blue]),
startPoint: .top,
endPoint: .bottom))
.rotationEffect(.degrees(rotation))
.mask {
RoundedRectangle(cornerRadius: 20, style: .continuous)
.stroke(lineWidth: 3)
.frame(width: width, height: height)
}
}
.ignoresSafeArea()
.onAppear{
withAnimation(.linear(duration: 4).repeatForever(autoreverses: false)){
rotation = 360
}
}
}
}
Ausgabe:

erwartete Ausgabe: