struct SpinnerView: View {
@State private var showSpinner = false
@State private var degree: Int = 270
@State private var spinnerLength = 0.6
var body: some View {
ZStack {
VStack {
Button {
showSpinner.toggle()
} label: {
Text("show spinner")
}
}
if showSpinner {
Circle()
.trim(from: 0.0, to: spinnerLength)
.stroke(.green, style: StrokeStyle(lineWidth: 8.0, lineCap: .square, lineJoin: .round))
.animation(Animation.easeIn(duration: 1.5).repeatForever(autoreverses: true), value: spinnerLength)
.frame(width: 60, height: 60)
.rotationEffect(Angle(degrees: Double(degree)))
.animation(Animation.linear(duration: 1).repeatForever(autoreverses: false), value: degree)
.onAppear {
degree = 270 + 360
spinnerLength = 0
}
}
}
}
}
More than 1 year has passed since last update.
【SwiftUI】よくある感じのくるくるインジケーター
Last updated at Posted at 2023-03-02
Register as a new user and use Qiita more conveniently
- You get articles that match your needs
- You can efficiently read back useful information
- You can use dark theme