TEAM LICENSES: Save money and learn new skills through a Hacking with Swift+ team license >>

Help to deal with TabView

Forums > SwiftUI

@Genka  

I'm just learning, please help me with the code

import SwiftUI

struct MainView: View {
    // Текущая вкладка.
    @State var currentTab: String = "Журнал расходов"
    // Пункт меню..
    @State var showMenu: Bool = false
    // Скрытие собственной панели вкладок.
    init() {
        UITabBar.appearance().isHidden = true
    }

    var body: some View {

        ZStack{
            // Пользовательское боковое меню.
            SideMenu(currentTab: $currentTab)

            // Просмотр главной вкладки.
            CustemTabView(currentTab: $currentTab, showMenu: $showMenu)
            // Задаем радиус угла.
                .cornerRadius(showMenu ? 25 : 0)
            // Выполнение 3D-вращения.
                .rotation3DEffect(.init(degrees: showMenu ? -15 : 0), axis: (x: 0, y: 1, z: 0),anchor: .trailing)
            // Раздвигающий вид.
            .offset(x: showMenu ? getRect().width / 1.7 : 0)
               .ignoresSafeArea()

        }
        // Всегда темный режим.
        .preferredColorScheme(.dark)
    }
}

#Preview {
            ContentView()
        }

extension View {
    func getSafeArea() -> UIEdgeInsets {
        guard let screen =
                UIApplication.shared.connectedScenes.first as?
                UIWindowScene else {
            return .zero
        }
        guard let safeArea = screen.windows.first?.safeAreaInsets
        else {
            return.zero
        }
        return safeArea
    }
}

this is where I hide all the tabs

   init() {
        UITabBar.appearance().isHidden = true
    }

But I don't want these tabs to be hidden

import SwiftUI

struct CarExpensesView: View {
    // Просмотр свойств
    @State private var currentTab: String = ""

    var body: some View {

            TabView(selection: $currentTab) {
                AvtoExpensesView(currentTab: $currentTab)
                    .badge(2)
                    .tabItem {
                        Label("Расходы", systemImage: "creditcard.fill")
                    }
                    .tag("Расходы")

                CategoriesView()
                    .badge(2)
                    .tabItem {
                        Label("Категории", systemImage: "list.clipboard.fill")
                    }
                    .tag("Категории")
            }
        }

    }

#Preview {
    CarExpensesView()
}

2      

In the CarExpensesView on the TabView try

.onAppear {
    UITabBar.appearance().isHidden = false
}

3      

@Genka  

unfortunately, this does not work, it only works for half, or rather, at the first start everything is fine, but when switching through the menu tabs stop hiding and now it doesn't work anymore

 init() {
        UITabBar.appearance().isHidden = true
    }

2      

Hacking with Swift is sponsored by String Catalog.

SPONSORED Get accurate app localizations in minutes using AI. Choose your languages & receive translations for 40+ markets!

Localize My App

Sponsor Hacking with Swift and reach the world's largest Swift community!

Reply to this topic…

You need to create an account or log in to reply.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.