本文介绍了如何在 SwiftUI 中禁用 ScrollView Bounce的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
任何Modifier
可用于阻止swiftUI
中ScrollView
的弹跳?
Any Modifier
available to stop bounce of ScrollView
in swiftUI
?
struct RoomDetailsView: View {
var body: some View {
ScrollView(showsIndicators: false) {
Image("test")
Text("Hello Text")
...
...
}
}
}
我尝试了以下代码,但对我不起作用.看起来它已被弃用
I tried below code but it not work for me. looks like it deprecated
ScrollView(alwaysBounceVertical: true) {
Image("test")
Text("Hello Text")
...
...
}
推荐答案
尝试使用这行代码:
UIScrollView.appearance().bounces = false
你可以这样使用它:-
You can use it like this:-
struct RoomDetailsView: View {
init() {
UIScrollView.appearance().bounces = false
}
var body: some View {
ScrollView(showsIndicators: false) {
Image("test")
Text("Hello Text")
...
...
}
}
}
或者您可以在 AppDelegate 中编写这一行,以将这种行为应用到您的应用中.
Or you can write this line in AppDelegate to apply this behaviour throughout into your app.
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
UIScrollView.appearance().bounces = false
}
这篇关于如何在 SwiftUI 中禁用 ScrollView Bounce的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!