Skip to content

Commit e635952

Browse files
author
Mithun
committed
Gestures and Events
1 parent 304e322 commit e635952

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

DesignCode/ContentView.swift

+16-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import SwiftUI
1111
struct ContentView: View {
1212

1313
@State var show = false
14+
@State var viewState = CGSize.zero
1415

1516
var body: some View {
1617
ZStack {
@@ -31,24 +32,38 @@ struct ContentView: View {
3132
.rotationEffect(Angle(degrees: show ? 15 : 0))
3233
.blendMode(.hardLight)
3334
.animation(.basic(duration: 0.7, curve: .easeInOut))
35+
.offset(x: viewState.width, y: viewState.height)
3436

3537
CardView()
36-
.background(show ? Color.red : Color("background8"))
38+
.background(show ? Color("background5") : Color("background8"))
3739
.cornerRadius(10)
3840
.shadow(radius: 20)
3941
.offset(x: 0, y: show ? -200 : -20)
4042
.scaleEffect(0.9)
4143
.rotationEffect(Angle(degrees: show ? 10 : 0))
4244
.blendMode(.hardLight)
4345
.animation(.basic(duration: 0.5, curve: .easeInOut))
46+
.offset(x: viewState.width, y: viewState.height)
4447

4548
CertificateView()
49+
.offset(x: viewState.width, y: viewState.height)
4650
.scaleEffect(0.95)
4751
.rotationEffect(Angle(degrees: show ? 5 : 0))
4852
.animation(.spring())
4953
.tapAction {
5054
self.show.toggle()
5155
}
56+
.gesture(
57+
DragGesture()
58+
.onChanged { value in
59+
self.viewState = value.translation
60+
self.show = true
61+
}
62+
.onEnded { _ in
63+
self.viewState = CGSize.zero
64+
self.show = false
65+
}
66+
)
5267
}
5368
}
5469
}

0 commit comments

Comments
 (0)