Skip to content

Instantly share code, notes, and snippets.

@StewartLynch
Created January 15, 2021 04:56
Show Gist options
  • Save StewartLynch/fefeba0185f6a6cba9bae2d7bae15966 to your computer and use it in GitHub Desktop.
Save StewartLynch/fefeba0185f6a6cba9bae2d7bae15966 to your computer and use it in GitHub Desktop.
Two Objects MagnificationGesture
struct ContentView: View {
@State private var currentMagnification: (CGFloat,CGFloat) = (1,1)
@GestureState private var pinchMagnification: (CGFloat,CGFloat) = (1,1)
var body: some View {
VStack {
Circle()
.fill(Color.green)
.shadow(radius: 20)
.frame(width: 100)
.scaleEffect(currentMagnification.0 * pinchMagnification.0)
.gesture(MagnificationGesture()
.updating($pinchMagnification, body: { (value, state, _) in
state.0 = value
})
.onEnded{ self.currentMagnification.0 *= $0 }
)
Circle()
.fill(Color.red)
.shadow(radius: 20)
.frame(width: 100)
.scaleEffect(currentMagnification.1 * pinchMagnification.1)
.gesture(MagnificationGesture()
.updating($pinchMagnification, body: { (value, state, _) in
state.1 = value
})
.onEnded{ self.currentMagnification.1 *= $0 }
)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment