[SwiftUI] Exclusive Gesture

RudinP·2025년 8월 22일
0

Study

목록 보기
346/363

특정 조건에 따라 인식할 제스처 선택

    var gestures: some Gesture {
        ExclusiveGesture(rotation.gesture, magnification.gesture)
    }
  • 기본적으로는 항상 첫번째 파라미터의 제스처만 실행

exclusively(before:)

  • 해당 메소드를 통해 두번째 파라미터의 제스처를 실행할지 결정 가능
  • 사용하지 않을 제스처를 before의 파라미터로 전달해야한다.
    var gestures: some Gesture {
        ExclusiveGesture(rotation.gesture, magnification.gesture)
    }
    
    var body: some View {
        VStack {
            VStack {
                if currentGestureType == .rotation {
                    logo
                        .rotationEffect(rotation.finalAngle)
                        .scaleEffect(magnification.finalScale)
                        .gesture(gestures)
                } else {
                    logo
                        .rotationEffect(rotation.finalAngle)
                        .scaleEffect(magnification.finalScale)
                        .gesture(magnification.gesture.exclusively(before: rotation.gesture))
                }
            }
  • 사실 if문으로 분기를 나눈 경우에는 각각 rotation, magnification gesture을 적었어도 무방하다...
  • 만약 속성에서 currentGestureType을 중심으로 분기문을 작성했다면 오류가 발생한다. (각각 <A,B>, <B,A>타입으로 별도의 타입으로 인식되어 opaque타입 리턴 X)
profile
iOS 개발자가 되기 위한 스터디룸...

0개의 댓글