How to disable ScrollView Bounce In SwiftUI

↘锁芯ラ 提交于 2020-06-15 21:24:08

问题


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")
       ...
       ...
}

回答1:


try using this line of code:

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")
         ...
         ...
          }
      }
  }

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
 }


来源:https://stackoverflow.com/questions/58799474/how-to-disable-scrollview-bounce-in-swiftui

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!