
Link : How to create 3D Rotation Effect in SwiftUI 2022 (Xcode)
struct ContentView: View {
@State private var degrees = 0.0
var body: some View {
VStack {
Spacer()
LinearGradient(
gradient: Gradient(colors: [.red, .yellow, .blue]),
startPoint: .topLeading,
endPoint: .bottomTrailing
)
.frame(width: 300, height: 200)
.cornerRadius(10)
.rotation3DEffect(
.degrees(degrees),
axis: (x: 0, y: 0, z: 1)//회전축.
)
Spacer()
Slider(value: $degrees, in: 0...1080)
.padding()
Button("Animate") {
withAnimation {
self.degrees += 180
}
}
}
}
}