如何在 SwiftUI 中禁用 ScrollView 弹跳
How to disable ScrollView Bounce In SwiftUI
任何 Modifier
可用于停止 swiftUI
中 ScrollView
的反弹?
struct RoomDetailsView: View {
var body: some View {
ScrollView(showsIndicators: false) {
Image("test")
Text("Hello Text")
...
...
}
}
}
我试过下面的代码,但它对我不起作用。看起来它已被弃用
ScrollView(alwaysBounceVertical: true) {
Image("test")
Text("Hello Text")
...
...
}
尝试使用这行代码:
UIScrollView.appearance().bounces = false
你可以这样使用它:-
struct RoomDetailsView: View {
init() {
UIScrollView.appearance().bounces = false
}
var body: some View {
ScrollView(showsIndicators: false) {
Image("test")
Text("Hello Text")
...
...
}
}
}
或者您可以在 AppDelegate 中编写此行以将此行为贯穿应用到您的应用程序中。
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
UIScrollView.appearance().bounces = false
}
您可以使用 SwiftUI-Introspect 库:
ScrollView {
// some content
}
.introspectScrollView { scrollView in
scrollView.alwaysBounceVertical = false
}
任何 Modifier
可用于停止 swiftUI
中 ScrollView
的反弹?
struct RoomDetailsView: View {
var body: some View {
ScrollView(showsIndicators: false) {
Image("test")
Text("Hello Text")
...
...
}
}
}
我试过下面的代码,但它对我不起作用。看起来它已被弃用
ScrollView(alwaysBounceVertical: true) {
Image("test")
Text("Hello Text")
...
...
}
尝试使用这行代码:
UIScrollView.appearance().bounces = false
你可以这样使用它:-
struct RoomDetailsView: View {
init() {
UIScrollView.appearance().bounces = false
}
var body: some View {
ScrollView(showsIndicators: false) {
Image("test")
Text("Hello Text")
...
...
}
}
}
或者您可以在 AppDelegate 中编写此行以将此行为贯穿应用到您的应用程序中。
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
UIScrollView.appearance().bounces = false
}
您可以使用 SwiftUI-Introspect 库:
ScrollView {
// some content
}
.introspectScrollView { scrollView in
scrollView.alwaysBounceVertical = false
}