Last active
May 20, 2023 11:04
-
-
Save MoussaHellal/511fcd9b4413af3217166a5b74dbe6af to your computer and use it in GitHub Desktop.
DraggableModifier.swift
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
// 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