3D Rotate Effect in SwiftUI

Zion·2023년 4월 23일
1

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
                }
            }
        }
    }
}
profile
어제보다만 나아지는

0개의 댓글