SwiftPamphletApp icon indicating copy to clipboard operation
SwiftPamphletApp copied to clipboard

LazyVStack 和 LazyHStack

Open ming1016 opened this issue 3 years ago • 0 comments

LazyVStack 和 LazyHStack 里的视图只有在滚到时才会被创建。

struct PlayLazyVStackAndLazyHStackView: View {
    var body: some View {
        ScrollView {
            LazyVStack {
                ForEach(1...300, id: \.self) { i in
                    PLHSRowView(i: i)
                }
            }
        }
    }
}

struct PLHSRowView: View {
    let i: Int
    var body: some View {
        Text("第 \(i) 个")
    }
    init(i: Int) {
        print("第 \(i) 个初始化了") // 用来查看什么时候创建的。
        self.i = i
    }
}

ming1016 avatar Feb 25 '22 03:02 ming1016