【发布时间】:2021-01-04 14:16:41
【问题描述】:
我正在尝试创建一个适用于 iPhone 和 iPad 的导航视图。目前我让它在 iPhone 上运行,但是在 iPad 上运行它时,导航视图无法正确显示我的主视图。见下文:
- 这是我加载应用程序的时候
- 如果我按下产品(左上角),它会打开产品选项卡。
- 当我点击某个产品时,它会转到此屏幕
- 如果我点击产品 1(见第三张图片),它会将所有详细信息打开到另一个导航栏中。
我想要实现的是图像 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)
}
}
}
提前感谢您的帮助:)
编辑:
这是 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,但您只能在单一视图层次结构中使用一个。 -
嗨,我已经用我的 ProductHeaderView 更新了我的帖子,我没有在里面使用 NavigationView。
-
你会准备最小可重现的例子吗?