简体   繁体   English

SwiftUI:如何在可重用视图上禁用列表滚动

[英]SwiftUI: How to Disable List Scrolling on Reusable View

I've got an interesting glitch in SwiftUI -我在 SwiftUI 中有一个有趣的故障 -

I'm using a List as part of my interface that is intended to be un-scrollable.我正在使用一个列表作为我的界面的一部分,该界面旨在不可滚动。 This is how I've designed it:这就是我设计它的方式:

List {
    ForEach(myArr) {
        ...
    }
}
.listStyle(.plain)
.onAppear { 
    UIScrollView.appearance().isScrollEnabled = false
    UIScrollView.appearance().showsVerticalScrollIndicator = false
}

Now, when I first load the view containing this list, it works perfectly;现在,当我第一次加载包含此列表的视图时,它运行良好; you cannot scroll this list.您无法滚动此列表。 However, if I navigate to a different page in my application and then back to the page containing this list (which creates a new instance of the view), scrolling becomes enabled.但是,如果我导航到应用程序中的不同页面,然后返回包含此列表的页面(创建视图的新实例),则启用滚动。

How can I fix this?我怎样才能解决这个问题?

Use .disabled(true) on the list to disable interaction with the list.在列表上使用.disabled(true)禁用与列表的交互。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM