Jac*_*ler 5 uipickerview swift swiftui swiftui-list swiftui-form
最近,我一直致力于创建一个复杂的视图,该视图允许我在表单下方使用选择器。在每种情况下,表单都只有两个选项,因此没有足够的数据向下滚动以获取更多数据。能够滚动这个表单而不是下面的 Picker 会让视图感觉很糟糕。我无法将选择器放置在表单内,否则 SwiftUI 会更改选择器上的样式。而且我找不到任何地方是否可以在不使用的情况下禁用列表/表单上的滚动:
.disable(condition)
Run Code Online (Sandbox Code Playgroud)
有没有办法在不使用上述语句的情况下禁用列表或表单上的滚动?这是我的代码供参考
VStack{
Form {
Section{
Toggle(isOn: $uNotifs.notificationsEnabled) {
Text("Notifications")
}
}
if(uNotifs.notificationsEnabled){
Section {
Toggle(isOn: $uNotifs.smartNotifications) {
Text("Enable Smart Notifications")
}
}.animation(.easeInOut)
}
} // End Form
.listStyle(GroupedListStyle())
.environment(\.horizontalSizeClass, .regular)
if(!uNotifs.smartNotifications){
GeometryReader{geometry in
HStack{
Picker("",selection: self.$hours){
ForEach(0..<24){
Text("\($0)").tag($0)
}
}
.pickerStyle(WheelPickerStyle())
.frame(width:geometry.size.width / CGFloat(5))
.clipped()
Text("hours")
Picker("",selection: self.$min){
ForEach(0..<61){
Text("\($0)").tag($0)
}
}
.pickerStyle(WheelPickerStyle())
.frame(width:geometry.size.width / CGFloat(5))
.clipped()
Text("min")
}
Run Code Online (Sandbox Code Playgroud)
这里是
使用我的帖子SwiftUI 中的方法:如何以编程方式滚动列表 [解决方案]?,可以添加以下扩展名
extension ListScrollingProxy {
func disableScrolling(_ flag: Bool) {
scrollView?.isScrollEnabled = !flag
}
}
Run Code Online (Sandbox Code Playgroud)
并将其用作上述演示的示例
struct DemoDisablingScrolling: View {
private let scrollingProxy = ListScrollingProxy()
@State var scrollingDisabled = false
var body: some View {
VStack {
Button("Scrolling \(scrollingDisabled ? "Off" : "On")") {
self.scrollingDisabled.toggle()
self.scrollingProxy.disableScrolling(self.scrollingDisabled)
}
Divider()
List(0..<50, id: \.self) { i in
Text("Item \(i)")
.background(ListScrollingHelper(proxy: self.scrollingProxy))
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
4356 次 |
最近记录: |