美文网首页SwiftUI
SwiftUI 2.0 中使用LazyVstack与LazyHs

SwiftUI 2.0 中使用LazyVstack与LazyHs

作者: 刘铁崧 | 来源:发表于2021-02-21 13:12 被阅读0次

解决问题:Vstack和Hstack会对内容一次性创建,当内部内容特别多并复杂时,会导致内存暴增,使用Lazy可以按需进行懒加载

注:按使用情况使用即可,有时用lazystack界面布局可能会被打乱

使用:

LazyVStack{
  ForEach(1...100,id:\.self){
    index in
    ContentView().frame(width:20,height:20)
  }
}

LazyHStack{
  ForEach(1...100,id:\.self){
    index in
    ContentView().frame(width:20,height:20)
  }
}

相关文章

网友评论

    本文标题:SwiftUI 2.0 中使用LazyVstack与LazyHs

    本文链接:https://www.haomeiwen.com/subject/dvcqfltx.html