Created
March 14, 2023 02:40
-
-
Save sturdysturge/56938b396e3ab8d752771963d1f029f3 to your computer and use it in GitHub Desktop.
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
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