Created
January 15, 2021 04:56
-
-
Save StewartLynch/fefeba0185f6a6cba9bae2d7bae15966 to your computer and use it in GitHub Desktop.
Two Objects MagnificationGesture
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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