8
6

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 1 year has passed since last update.

【SwiftUI】iOS17の新APIを使用してScrollViewを操る

Last updated at Posted at 2023-06-10

はじめに

iOS17からscrollTransitionというモディファイアが追加されたので使ってみました!

サンプルアプリ

画面外になるタイミングで少し小さくなるような動きです
Simulator Screen Recording - iPhone 14 Pro - 2023-06-10 at 22.31.16.gif

実装

import SwiftUI

struct ContentView: View {
    var body: some View {
        ScrollView(.vertical) {
            VStack(spacing: 10) {
                ForEach(0..<50, id: \.self) { index in
                    Text("Cell: \(index)")
                        .frame(maxWidth: .infinity)
                        .frame(height: 200)
                        .cornerRadius(20)
                        .foregroundColor(.white)
                        .background(.thinMaterial, in: RoundedRectangle(cornerRadius: 10))
                        .overlay(.white.opacity(0.5), in: RoundedRectangle(cornerRadius: 10).stroke(style: .init()))
                        .padding(.horizontal, 20)
+                       .scrollTransition { emptyVisualEffect, scrollTransitionPhase in
+                           emptyVisualEffect.scaleEffect(scrollTransitionPhase.isIdentity ? 1 : 0.8)
+                       }
                }
            }
        }
        .background(LinearGradient(gradient: Gradient(colors: [.pink, .yellow, .orange]), startPoint: .topLeading, endPoint: .bottomTrailing))
    }
}

ドキュメント

おわり

これはめっちゃ便利なAPIです!
いろんなことができそうです!

スクリーンショット 2023-06-06 17.23.08.png
「Appleが一般に開示した情報」に該当してると思うので大丈夫だとは思いますが、
もしアウトだったらコメントで教えて欲しいです。

8
6
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
8
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?