How to use MagnificationGesture in SwiftUI | Continued Learning #2
State
를 통해 조정한다. 즉 값이 바뀌면 곧바로 오브젝트 크기가 바뀔 수 있도록 렌더링. .scaleEffect(1 + currentAmount)
.gesture(
MagnificationGesture()
.onChanged { value in
currentAmount = value - 1
}
.onEnded { value in
currentAmount = 0
}
)
import SwiftUI
struct MagnificationGestureBootCamp: View {
@State private var currentAmount: CGFloat = 0
var body: some View {
VStack(spacing: 10) {
HStack {
Circle().frame(width: 35, height: 35)
Text("Swiftful Thinking")
Spacer()
Image(systemName: "ellipsis")
}
.padding(.horizontal)
Rectangle().frame(height: 300)
.frame(height: 300)
.scaleEffect(1 + currentAmount)
.gesture(
MagnificationGesture()
.onChanged { value in
currentAmount = value - 1
}
.onEnded { value in
currentAmount = 0
}
)
HStack {
Image(systemName: "heart.fill")
Image(systemName: "text.bubble.fill")
Spacer()
}
.padding(.horizontal)
.font(.headline)
Text("This is the caption for my photo.")
.frame(maxWidth: .infinity, alignment: .leading)
.padding(.horizontal)
}
}
}
크기가 원상복구될 때(
onEnded
) 애니메이션 효과를 주면 보다 깔끔하게 처리할 수 있을 것 같다.