MagnificationGesture를 사용하면 화면 또는 사진 등을 확대 축소할 수 있습니다

 

 

onChanged는 확대 및 축소할 때 감지되는 값에 따라서 value의 값이 달라집니다.

onEnded는 확대 및 축소 동작을 완료했을 때 실행됩니다.

struct ContentView: View {
    
    @State var currentAmout: CGFloat = 0
    @State var lastAmount: CGFloat = 0
    
    var body: some View {
        VStack(spacing: 10) {
            HStack {
                Circle().frame(width: 35, height: 35)
                Text("iOS-Developer")
                Spacer()
                Image(systemName: "ellipsis")
            }
            .padding(.horizontal)
            Rectangle()
                .frame(height: 300)
                .scaleEffect(1 + currentAmout)
                .gesture(
                    MagnifyGesture()
                        .onChanged { value in
                            currentAmout = value.magnification - 1.0
                        }
                        .onEnded({ value in
                            currentAmout = 0
                        })
                )
        }
    }
}

 

결과

ytw_developer