Skip to content

Instantly share code, notes, and snippets.

@MoussaHellal
Last active May 20, 2023 11:04
Show Gist options
  • Save MoussaHellal/511fcd9b4413af3217166a5b74dbe6af to your computer and use it in GitHub Desktop.
Save MoussaHellal/511fcd9b4413af3217166a5b74dbe6af to your computer and use it in GitHub Desktop.
DraggableModifier.swift
// Created by Moussa on 20/5/2023.
import SwiftUI
struct DraggableModifier: ViewModifier {
@State private var offset = CGSize.zero
func body(content: Content) -> some View {
content
.cornerRadius(7)
.cornerRadius(20)
.shadow(color: .gray, radius: 10, x: 8, y: 15)
.padding()
.rotationEffect(.degrees(Double(offset.height / 20)))
.offset(x: 0, y: offset.height)
.gesture(
DragGesture()
.onChanged { gesture in
offset = gesture.translation
}
.onEnded { _ in
withAnimation(.easeIn(duration: 0.3)) {
offset = .zero
}
}
)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment