SwiftUI

SwiftUI 2.0 中使用LazyVstack与LazyHs

2021-02-21  本文已影响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)
  }
}

上一篇 下一篇

猜你喜欢

热点阅读