我正在尝试创建一个适用于iPhone和iPad的导航视图。目前,我已经在iPhone上实现了它,但是在iPad上运行时,导航视图无法正确呈现我的主视图。请参见下面的内容:
- 这是我加载应用程序时的情况
- 如果我按产品(左上角),它会打开产品选项卡。
- 当我单击产品时,它会进入此屏幕
- 如果我单击产品1(在第3个图像中看到),它会将所有详细信息打开到另一个导航栏中。
我想要实现的是,图像4不在导航选项卡中,而是全屏显示。 我尝试从代码中删除NavigationView,这似乎解决了问题并使其全屏。 但是,我随后失去了导航视图按钮,无法让用户查看其他产品。
这是我的代码缩短版本(没有所有文本/图像详细信息):
var body: some View {
NavigationView {
ScrollView(.vertical, showsIndicators: false) {
VStack(alignment: .center, spacing: 20) {
ProductHeaderView(product: product)
VStack(alignment: .leading, spacing: 15) {
Text(product.title)
.font(.largeTitle)
.fontWeight(.heavy)
.foregroundColor(product.gradientColors[1])
Text(product.headline)
.font(.headline)
.multilineTextAlignment(.leading)
}
.padding(.horizontal, 20)
.frame(maxWidth: 640, alignment: .center)
}
.navigationBarTitle(product.title, displayMode: .inline)
.navigationBarHidden(true)
}
.edgesIgnoringSafeArea(.top)
}
}
}
Thank you in advance for your help :)
EDIT:
以下是ProductHeaderView.swift代码:
var body: some View {
ZStack {
LinearGradient(gradient: Gradient(colors: product.gradientColors), startPoint: .topLeading, endPoint: .bottomTrailing)
TabView{
ForEach(0..<product.images.count, id: \.self) { item in
Image(product.images[item])
.resizable()
.scaledToFit()
.shadow(color: Color(red: 0, green: 0, blue: 0, opacity: 0.15), radius: 8, x: 6, y: 8)
.scaleEffect(isAnimatingImage ? 1.0 : 0.6)
}//: FOR LOOP
}//: TAB VIEW
.tabViewStyle(PageTabViewStyle())
.padding(.vertical, 0)
} //: ZSTACK
.frame(height: 414)
.onAppear(){
withAnimation(.easeOut(duration: 0.5)){
isAnimatingImage = true
}
}
}
ProductHeaderView
中有另一个NavigationView
,但是在单个视图层次结构中只能使用一个。 - Asperi