0

我是 swift 新手,我正在尝试将我的视图包装在 Scrollview 中。问题是,当我将内容包装在滚动视图中时,内容会缩小。我有下面的图片。 不带滚动视图的视图

使用滚动视图查看

示例代码:

 ScrollView(.vertical) {
        GeometryReader { metrics in
            HStack{
                Button(action:{
                    isVisible = true
                }, label: {
                    VStack(alignment: .center, spacing: 10){
                        Image(systemName: "book.fill")
                            .resizable()
                            .frame(width: 28, height: 22)
                            .padding(EdgeInsets(top: 15, leading: 0, bottom: 0, trailing: 0))
                            .foregroundColor(CustomColor.primaryColor)
                            
                        
                        Text("Daily Reading")
                            .padding(EdgeInsets(top: 0, leading: 0, bottom: 15, trailing: 0))
                            .foregroundColor(CustomColor.primaryColor)
                    }.frame(maxWidth: metrics.size.width/2.3, maxHeight: .infinity)
                        .background(RoundedRectangle(cornerRadius: 15)
                                        .fill(Color.white)
                                        .shadow(color: .gray, radius: 2, x: 0, y: 2))
                })
                
            Spacer()
                Button(action: {
                    
                }, label: {
                    VStack(alignment: .center, spacing: 10){
                        Image("church")
                            .resizable()
                            .frame(maxWidth: 28, maxHeight: 22)
                            .padding(EdgeInsets(top: 15, leading: 0, bottom: 0, trailing: 0))
                            .foregroundColor(CustomColor.primaryColor)
                        
                        Text("Church Prayers")
                            .padding(EdgeInsets(top: 0, leading: 0, bottom: 15, trailing: 0))
                            .foregroundColor(CustomColor.primaryColor)
                    }.frame(maxWidth: metrics.size.width/2.3, maxHeight: .infinity)
                        .background(RoundedRectangle(cornerRadius: 15)
                                        .fill(Color.white)
                                        .shadow(color: .gray, radius: 2, x: 0, y: 2))
                })
                
            }.frame(maxHeight: metrics.size.width/2)
            .padding(.horizontal, 15)
        .padding(.vertical, 7.5)
        }
    }

我已尝试删除 GeometryReader,但仍然得到相同的结果,而且我似乎无法在线找到任何有用的解决方案。谢谢

4

1 回答 1

1

在 上HStack{...},尝试替换.frame(maxHeight: metrics.size.width/2).frame(height: metrics.size.width/2)

于 2022-02-20T14:08:28.463 回答