我在我的应用程序中使用相机。该应用程序允许您借助 SwiftUI 中的 TabView
导航到此相机 View 。然而,问题是,当我在相机 View 中时,我想隐藏 TabView
。到目前为止,我一直在努力寻找解决方案,但我似乎找不到任何解决方案。
这是一个screenshot of the code and the view with the tabview
注意:屏幕截图包含预览图像。当我在真实设备上运行时,相机工作正常。问题是我需要在进入相机 View 后隐藏标签栏。
下面是我使用的代码示例:
import SwiftUI
struct AppView: View {
var body: some View {
TabView{
Home()
.tabItem {
// Add icon
Text("Home")
}
MomentsCam()
.tabItem {
// Add icon
Text("Camera")
}.navigationBarHidden(true)
Moments()
.tabItem{
//Add icon
Text("Moments")
}
}
}
}
最佳答案
我更新了my solution使用 TabView 适合您的情况。同样的想法:您正在使用 ZStack
和 @State var selection
。这个想法是使用 TabView
和 YourCameraView
的 .opacity
(这只是 Image(systemName: "plus.circle")
在我的例子中):
struct TabViewModel: View {
@State var selection: Int = 0
var body: some View {
ZStack {
GeometryReader { geometry in
TabView(selection: self.$selection) {
Text("list")
.tabItem {
Image(systemName: "list.bullet.below.rectangle")
}.tag(0)
Text("plus")
.tabItem {
Image(systemName: "camera")
}.tag(1)
Text("more categories!")
.tabItem {
Image(systemName: "square.grid.2x2")
}.tag(2)
}
.opacity(self.selection == 1 ? 0.01 : 1)
Image(systemName: "plus.circle")
.resizable()
.frame(width: 60, height: 60)
.shadow(color: .gray, radius: 2, x: 0, y: 5)
.offset(x: geometry.size.width / 2 - 30, y: geometry.size.height - 80)
.onTapGesture {
self.selection = 0
}
.opacity(self.selection == 1 ? 1 : 0)
}
}
}
}
当您点击相机标签时,TabView
变得不可见
关于ios - 在 SwiftUI 的特定页面上隐藏标签栏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59042793/