ios - 在 SwiftUI 的特定页面上隐藏标签栏

标签 ios swiftui tabview

我在我的应用程序中使用相机。该应用程序允许您借助 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。这个想法是使用 TabViewYourCameraView.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/

相关文章:

swift - 如何在swiftUI中使用分页选项卡 View 时阻止页面上下滚动

ios - 如何在 Swift 中获取 C 指针的原始值?

ios - 在 iOS 版 Instagram 应用程序上分享视频网址

ios - 如何使用 NSMutableURLRequest 对 GET 请求中的特殊字符进行编码

带有 Xcode 11 beta 7 的 SwiftUI 不更新 List/ForEach 的内容

带有背景颜色的 Android tabview 图标

ios - 无法使用 cocoapods Xcode 6.1.1 存档

swiftui - 状态变量值正在丢失

swift - 如何使用 combine Publisher 更改线程?

安卓 list .xml