0
1

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】ScrollViewのバウンスを無効にする

Last updated at Posted at 2023-08-03

はじめに

バウンスありとなしではアプリの印象がとても変わります。
SwiftUIのScrollViewはバウンスがありで、変更することができないのでSwiftUI-Introspectを使用してバウンスを無しにしてみます

Simulator Screen Recording - iPhone 14 Pro - 2023-08-03 at 21.06.12.gif Simulator Screen Recording - iPhone 14 Pro - 2023-08-03 at 21.05.50.gif

ライブラリのインストール

全体的な流れはこちらを参考にしてください

注意
SwiftUIIntrospectのみチェックをいれます
スクリーンショット 2023-08-01 16.18.26.png

実装

import SwiftUI
import SwiftUIIntrospect

struct ContentView: View {
    @State private var isPresented = false

    var body: some View {
        ScrollView {
            ForEach(0..<50) { _ in
                Text("サンプルセル")
            }
        }
        .introspect(.scrollView, on: .iOS(.v13, .v14, .v15, .v16, .v17)) { scrollView in
            scrollView.bounces = false
        }
    }
}

おわり

これは結構好き嫌い分かれるところだと思うのでアプリ内で切り替えできるようにするといいかもしれません。

0
1
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
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?