Skip to content

Instantly share code, notes, and snippets.

@MoussaHellal
Last active May 20, 2023 10:32
Show Gist options
  • Save MoussaHellal/06ece58431da0f2f5b50b79b198e4314 to your computer and use it in GitHub Desktop.
Save MoussaHellal/06ece58431da0f2f5b50b79b198e4314 to your computer and use it in GitHub Desktop.
draggable shadowed Image
// 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