Last active
May 20, 2023 10:32
-
-
Save MoussaHellal/06ece58431da0f2f5b50b79b198e4314 to your computer and use it in GitHub Desktop.
draggable shadowed Image
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 ContentView: View { | |
@State private var offset = CGSize.zero | |
var body: some View { | |
VStack { | |
Image("cappucino") | |
.resizable() | |
.aspectRatio(contentMode: .fit) | |
} | |
.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