Код: Выделить всё
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
}
}
}
}
Ожидаемый выход:
Подробнее здесь: https://stackoverflow.com/questions/776 ... ion-in-ios