Skip to content

Instantly share code, notes, and snippets.

@sturdysturge
Created March 14, 2023 02:40
Show Gist options
  • Save sturdysturge/56938b396e3ab8d752771963d1f029f3 to your computer and use it in GitHub Desktop.
Save sturdysturge/56938b396e3ab8d752771963d1f029f3 to your computer and use it in GitHub Desktop.
import SwiftUI
@available(iOS 16.0, *)
extension ContentView: View {
var body: some View {
VStack {
Rectangle()
GeometryReader { proxy in
let dragGesture = DragGesture()
.updating($dragOffset) { (value, state, transaction) in
state = value.translation
}
.onEnded { value in
dragEnded(value.translation, proxy.frame(in: .global))
}
Text("Done!")
.font(.headline)
.foregroundColor(.white)
.padding(25)
.background(Color.green)
.cornerRadius(5)
.opacity(0.9)
.rotationEffect(draggingRotation)
.rotationEffect(endSpinRotation)
.position(x: position.width + dragOffset.width,
y: position.height + dragOffset.height)
.gesture(dragGesture)
}
.overlay(Button("Reset") { position = .zero })
.frame(maxWidth: .infinity,
maxHeight: .infinity,
alignment: .center)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment