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】TabViewのPageスタイルのバウンスを無効化する

Posted at

はじめに

何もないところにスクロールしようとするとバウンドする感じが気に入らないのでこれを無くしたいです。
Simulator Screen Recording - iPhone 14 Pro - 2023-08-11 at 21.58.23.gif

SwiftUIIntrospectを使うことでなくせたので記事にしておきます。

実装

import SwiftUI
import SwiftUIIntrospect

struct ContentView: View {
    var body: some View {
        TabView {
            Color.red
            
            Color.yellow
            
            Color.blue
        }
        .tabViewStyle(.page(indexDisplayMode: .never))
        .introspect(.tabView(style: .page), on: .iOS(.v14, .v15, .v16, .v17)) {
            $0.bounces = false
        }
    }
}

Simulator Screen Recording - iPhone 14 Pro - 2023-08-11 at 22.01.20.gif

おわり

これ公式が提供してもいいんじゃない?

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?