Skip to content

Instantly share code, notes, and snippets.

@b3ll
Created March 6, 2020 04:51
Show Gist options
  • Select an option

  • Save b3ll/2af41f5a5654d9792c000f8acbfcc0de to your computer and use it in GitHub Desktop.

Select an option

Save b3ll/2af41f5a5654d9792c000f8acbfcc0de to your computer and use it in GitHub Desktop.
Quick test to verify SwiftUI Gestures + Velocity
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