作者:普罗土 | 来源:互联网 | 2023-10-15 14:25
我正在使用NavigatonView和NavigationLink,我的观点是这样的:
ScrollView{
VStack{
// MARK: - Survey and tips Navigation
HStack(spacing:9){
NavigationLink(destination:Container.sharedContainer.resolve(SurveyListView.self,argument: $VM.occurrences)!){
iconHome(image: "img-survey",icon: "icon-survey",text: "surveys_upper_case")}
NavigationLink(destination:Container.sharedContainer.resolve(SurveyListView.self,argument: $VM.occurrences)!){
iconHome(image: "img-tip",icon: "icon-tip",text: "tips_upper_case")}
}
.frame(maxWidth: .infinity,maxHeight: .infinity)
}
.padding(.horizontal,37)
.background(Color.red)
}
iconHome是另一个实现视图协议的结构:
struct iconHome : View{
var image:String
var icon:String
var text:LocalizedStringKey
var body : some View{
GeometryReader{ geometry in
ZStack{
Image(self.image)
.renderingMode(.original)
.resizable()
.frame(width: geometry.size.width,height:geometry.size.width)
.aspectRatio(contentMode: .fit)
.cornerRadius(20)
VStack{
Image(self.icon)
.renderingMode(.original)
.resizable()
.frame(width: geometry.size.width / 5,height:geometry.size.width / 5 )
.aspectRatio(contentMode: .fit)
Text(self.text)
.foregroundColor(.white)
.modifier(OpenSansBoldmodifier(fontSize: 12))
}
}
.shadow(radius: 5,x: 5,y: 5)
}
}
}
我得到一个奇怪的结果:
我不为什么,但是包含两个导航链接的HStack只有红色矩形高...因此很难单击他...关于HStack为什么没有高矩形的任何想法吗?
似乎缺少geometry
的填充模式
GeometryReader{ geometry in
....
}.aspectRatio(contentMode: .fill)