Created
March 6, 2020 04:51
-
-
Save b3ll/2af41f5a5654d9792c000f8acbfcc0de to your computer and use it in GitHub Desktop.
Quick test to verify SwiftUI Gestures + Velocity
This file contains hidden or 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
| import SwiftUI | |
| import UIKit | |
| import PlaygroundSupport | |
| struct GestureSwitch: View { | |
| @GestureState var offsetY: CGFloat? = nil | |
| var body: some View { | |
| ZStack { | |
| Rectangle() | |
| .foregroundColor(.gray) | |
| Rectangle() | |
| .foregroundColor(.purple) | |
| .offset(x: 0.0, y: offsetY ?? 0.0) | |
| .animation(offsetY == nil ? .spring(response: 0.95, dampingFraction: 0.85, blendDuration: 0.0) : nil) | |
| .gesture( | |
| DragGesture() | |
| .updating($offsetY) { (gestureValue, offsetY, _) in | |
| offsetY = gestureValue.translation.height | |
| } | |
| ) | |
| } | |
| } | |
| } | |
| PlaygroundPage.current.setLiveView(GestureSwitch()) | |
| PlaygroundPage.current.needsIndefiniteExecution = true |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment