SwiftUI 100 레시피/Gestures

SwiftUI Gestures - 3D 로테이션(회전)

tonylee9239 2022. 6. 20. 12:41

X, Y, Z 축 값을 변형하여 로테이션 효과를 준다

 

 

import SwiftUI

 

struct ContentView: View {

    

    @State private var flipped: Bool = false

    

    var body: some View {

        VStack{

            HStack{

                

            }.frame(maxWidth: 300, maxHeight: 150)

                .background(LinearGradient(gradient: Gradient(colors:[Color.red, Color.blue]), startPoint: .leading, endPoint: .trailing))

                .clipShape(RoundedRectangle(cornerRadius: 25.0, style: .continuous))

                .rotation3DEffect(

                    flipped ? Angle(degrees:  180): .zero,

                    axis: (x: 0.0, y: 0.0, z: 1.0))

                .animation(.default)

                .onTapGesture {

                    flipped.toggle()

                }

        }

    }

}

 

struct ContentView_Previews: PreviewProvider {

    static var previews: some View {

        ContentView()

    }

}

 

원래 모양 클릭시 z축 방향으로 회전
회전한 상태