Ios 全屏视图在HStack和水平滚动视图内不工作

Ios 全屏视图在HStack和水平滚动视图内不工作,ios,scrollview,swiftui,horizontallist,hstack,Ios,Scrollview,Swiftui,Horizontallist,Hstack,我一直在尝试使用水平列表等创建入职流程。我创建了一个名为OnboardingView的视图,其中有一个带图像的VStack和两个文本视图 struct OnboardingView: View { var body: some View { GeometryReader { geometry in VStack(spacing: 10) { Spacer() Image("1") .resiz

我一直在尝试使用水平列表等创建入职流程。我创建了一个名为
OnboardingView
的视图,其中有一个带图像的VStack和两个文本视图

struct OnboardingView: View {
var body: some View {
    GeometryReader { geometry in
        VStack(spacing: 10) {
            Spacer()
            Image("1")
                .resizable()
                .frame(width: 300, height: 300)
                .clipShape(Circle())
                .padding(20)
            Text("Travel the World")
                .frame(width: geometry.size.width, height: 20, alignment: .center)
                .font(.title)
            Text("Explore the world and get to know different cultures and people from all around the world")
                .lineLimit(nil)
                .padding(.leading, 15)
                .padding(.trailing, 15)
                .font(.system(size: 16))
                .frame(width: geometry.size.width, height: 50, alignment: .center)
                .multilineTextAlignment(.center)
            Spacer()

        }.background(Color.red)
}
} }

这是我通过上述代码得到的结果:

现在,我正试图使用HStack将此视图添加到ScrollView中

struct ContentView: View {

var body: some View {
   ScrollView(.horizontal, showsIndicators: false) {
        HStack {
            OnboardingView()
            OnboardingView()
        }
    }.background(Color.black)

  }
 }
上述代码的结果是荒谬的!这就是我得到的。如何着手解决这个问题?谢谢你的帮助!谢谢


一种可能的解决方案是将
车载视图的
宽度设置为
几何体、大小、宽度

var body: some View {
    GeometryReader { geometry in
        ScrollView(.horizontal, showsIndicators: false) {
            HStack {
                OnboardingView()
                    .frame(width: geometry.size.width)
                OnboardingView()
                    .frame(width: geometry.size.width)
            }
        }.background(Color.black)
    }
}
结果