我有一个iOS应用程序,在那里我有2个列表,我在屏幕上显示,基本上是一个垂直的滚动视图,里面是一个水平的滚动视图,有2个列表:
垂直滚动视图:
- 顶部标题视图
1.水平滚动视图:
1.样本配置文件视图
1.样本配置文件视图B
VStack(alignment: .center){
VStack(alignment: .center){
Image(systemName: "star.circle.fill")
.resizable()
.scaledToFit()
.frame(width: 200, height: 200)
.clipShape(.circle)
Text("Some Guy")
.font(.largeTitle)
}.padding(.vertical)
}
字符串
水平滚动视图:
组成部分1:
@ViewBuilder
func SampleProfileView() -> some View{
var arrayData: [Int] = Array(1…10);
LazyVStack{
Text("About”)
.fontWeight(.bold)
.frame(maxWidth: .infinity, alignment: .leading)
.foregroundColor(.black)
.padding(.horizontal)
VStack{
ForEach(arrayData, id: \.self){item in
ZStack{
RoundedRectangle(cornerRadius: 15)
.fill(color.gradient)
// .frame(height: 100)
Text("\(item)")
.foregroundColor(.black)
.fontWeight(.bold)
.padding(.horizontal)
}
}
}
}
}
型
构成部分2:
@ViewBuilder
func SampleProfileViewB() -> some View{
var arrayData: [Int] = Array(1…50);
LazyVStack{
Text("About")
.fontWeight(.bold)
.frame(maxWidth: .infinity, alignment: .leading)
.foregroundColor(.black)
.padding(.horizontal)
VStack{
ForEach(arrayData, id: \.self){item in
ZStack{
RoundedRectangle(cornerRadius: 15)
.fill(color.gradient)
// .frame(height: 100)
Text("\(item)")
.foregroundColor(.black)
.fontWeight(.bold)
.padding(.horizontal)
}
}
}
}
}
型
=主视图组件我在以下主视图组件中使用这两个组件:
NavigationStack{
ScrollView(.vertical){
LazyVStack{
TopHeaderView()
ScrollView(.horizontal){
LazyHStack{
SampleProfileView()
.id(0)
.containerRelativeFrame(.horizontal)
SampleProfileViewB()
.id(1)
.containerRelativeFrame(.horizontal)
}
}
.scrollIndicators(.visible)
.scrollTargetBehavior(.paging)
.scrollTargetLayout()
}
}
}
型
我的问题:
我的问题是,我如何让框架的高度调整到SampleProfileView()
和SampleProfileViewB()
中不同列表大小的大小
正如你在图片中看到的,scrollview列表中的一些元素被隐藏了,我无法滚动。
正如你在下面的截图中看到的,它没有到达列表的末尾,它应该一直走到第50个元素,它只到达了第40个元素。
截图:
1条答案
按热度按时间e4eetjau1#
回答我的问题。问题原来是因为我使用了LazyHStack。一旦我在**ScrollView(.horizontal)**中切换到HStack,它就被修复了,现在所有元素都显示出来了。