0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

SwiftUIでAppStoreのTodayのカードみたいなやつ

Last updated at Posted at 2020-09-03

実装したいこと

AppStoreのTodayタブのカードのように、押したら少し小さくなり、はなすと元に戻るようなやつ。

どうやったか

DrugGestureとか使ってやろうと思ったけど、ScroolViewと合わせて使うとスクロールしなくなる問題があった。
ButtonStyleを使えば、簡単にできた。

.scaleEffect(configuration.isPressed ? 0.95 : 1.0)がみそ。

struct SprintButtonStyle: ButtonStyle {
    func makeBody(configuration: Self.Configuration) -> some View {
        configuration.label
            
            .scaleEffect(configuration.isPressed ? 0.95 : 1.0)
            .animation(.default)
    }
}

struct TodayCardView: View {
    var body: some View {
        Button(action: {
            print("Button action")
        }) {
            Text("テキスト")
                .font(.title)
                .padding()
                .frame(width: 250, height: 300)
                .background(Color.green)
        }
        .buttonStyle(SprintButtonStyle()
        )
    }
}
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?