放入ZStack时swiftui列表不起作用 [英] swiftui list not working when put into ZStack
本文介绍了放入ZStack时swiftui列表不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用ZStack将列表和颜色组合在一起,完成后,列表将不会滚动,并且在单击文本时没有任何输出.
I use ZStack to combine a list and Color, after doing it, List will not scroll and there's no output when clicking the text.
有人知道如何解决吗?
谢谢
struct ContentView: View {
var body: some View {
ZStack{
List{
ForEach(1...30, id: \.self){ i in
Text("ROW \(i)")
.font(.system(size: 40))
.onTapGesture {
print("clicked \(i)")
}
}
}
Color.black.opacity(0.2)
}
}
}
推荐答案
将颜色移到列表"之前,它将起作用.请参阅下面更改的代码.
Move Color before List and it will work. See the altered code below.
import SwiftUI
struct ContentView: View {
var body: some View {
ZStack{
Color.black.opacity(0.2)
List{
ForEach(1...30, id: \.self) { i in
Text("ROW \(i)")
.font(.system(size: 40))
.onTapGesture {
print("clicked \(i)")
}
}
}
}
}
}
这篇关于放入ZStack时swiftui列表不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文