Skip to content

Instantly share code, notes, and snippets.

@KentarouKanno
Last active June 24, 2019 22:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save KentarouKanno/fe601bae8cf1cc9ac2608569197b78c8 to your computer and use it in GitHub Desktop.
Save KentarouKanno/fe601bae8cf1cc9ac2608569197b78c8 to your computer and use it in GitHub Desktop.

Card View

参考URL: Setting up Gestures in SwiftUI

import SwiftUI

struct CardView : View {
    @State var cardOffset: Length = 50
    
    var body: some View {
        ZStack {
            
            Card()
                .foregroundColor(Color.purple)
            
            Card()
                .foregroundColor(Color.blue)
                .offset(y: cardOffset)
                .animation(.spring())
                .gesture(
                    DragGesture()
                        .onChanged { value in
                            self.cardOffset = value.translation.height
                        }
                        .onEnded { _ in
                            self.cardOffset = 50
                    }
            )
        }
    }
}

struct Card: View {
    var body: some View {
        Rectangle()
            .cornerRadius(30)
    }
}

#if DEBUG
struct CardView_Previews : PreviewProvider {
    static var previews: some View {
        CardView()
    }
}
#endif
イメージ
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment