treattrick / hide-tabbar-in-swiftui Goto Github PK
View Code? Open in Web Editor NEWThis tutorial provides a solution to hide TabBars when using TabView in SwiftUI
This tutorial provides a solution to hide TabBars when using TabView in SwiftUI
There's a .toolbar(.hidden, for: .tabBar)
modifier.
Put this modifier in the destination View.
And then
In the ContentView
struct ContentView: View {
@State private var selection: Int = 0
var body: some View {
TabView(selection: $selection) {
HomeView()
.tabItem {
Image(systemName: "house")
}
.toolbarBackground(.visible, for: .tabBar)
.tag(0)
NavigationStack {
ForumView()
}
.tabItem {
Image(systemName: "text.bubble")
}
.toolbarBackground(.visible, for: .tabBar)
.tag(1)
NavigationStack {
ProjectsView()
}
.tabItem {
Image(systemName: "folder.fill")
}
.toolbarBackground(.visible, for: .tabBar)
.tag(2)
LoginRootView()
.tabItem {
Image(systemName: "person.crop.circle")
}
.toolbarBackground(.visible, for: .tabBar)
.tag(3)
}
.tint(Color.orange)
.animation(.spring(response: 0.3, dampingFraction: 0.6), value: selection)
.toolbar(.visible, for: .tabBar)
}
.animation(.spring(response: 0.3, dampingFraction: 0.6), value: selection)
Put this animation in the TabView's selection property
Your exact solution worked over a year ago, but unfortunately, it appears to be broken with the latest updates from Apple. I fear this is not a viable solution for iOS 15. Can you verify this? Or, have I overlooked something?
The toolbar items from top disappear by this method. How to add them?
I just cloned this repo and open it using Xcode 12.4, ran it on a simulator iPhone 12 with iOS 14.4. However, once build secceeded, I got the error info below:
2021-03-21 11:39:59.111302+0800 HideTabBarInNavigationView[18305:556332] [LayoutConstraints] Unable to simultaneously satisfy constraints.
Probably at least one of the constraints in the following list is one you don't want.
Try this:
(1) look at each constraint and try to figure out which you don't expect;
(2) find the code that added the unwanted constraint or constraints and fix it.
(
"<NSLayoutConstraint:0x60000016c3c0 'BIB_Trailing_CB_Leading' H:[_UIModernBarButton:0x7fad35f28ba0]-(6)-[_UIModernBarButton:0x7fad35f26940'Tab1'] (active)>",
"<NSLayoutConstraint:0x60000016c410 'CB_Trailing_Trailing' _UIModernBarButton:0x7fad35f26940'Tab1'.trailing <= BackButton.trailing (active, names: BackButton:0x7fad35f251f0 )>",
"<NSLayoutConstraint:0x600000168730 'UINav_static_button_horiz_position' _UIModernBarButton:0x7fad35f28ba0.leading == UILayoutGuide:0x600001b01960'UIViewLayoutMarginsGuide'.leading (active)>",
"<NSLayoutConstraint:0x600000168780 'UINavItemContentGuide-leading' H:[BackButton]-(0)-[UILayoutGuide:0x600001b50700'UINavigationBarItemContentLayoutGuide'] (active, names: BackButton:0x7fad35f251f0 )>",
"<NSLayoutConstraint:0x600000141d10 'UINavItemContentGuide-trailing' UILayoutGuide:0x600001b50700'UINavigationBarItemContentLayoutGuide'.trailing == _UINavigationBarContentView:0x7fad35d13530.trailing (active)>",
"<NSLayoutConstraint:0x600000168f00 'UIView-Encapsulated-Layout-Width' _UINavigationBarContentView:0x7fad35d13530.width == 0 (active)>",
"<NSLayoutConstraint:0x600000165ef0 'UIView-leftMargin-guide-constraint' H:|-(0)-[UILayoutGuide:0x600001b01960'UIViewLayoutMarginsGuide'](LTR) (active, names: '|':_UINavigationBarContentView:0x7fad35d13530 )>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x60000016c3c0 'BIB_Trailing_CB_Leading' H:[_UIModernBarButton:0x7fad35f28ba0]-(6)-[_UIModernBarButton:0x7fad35f26940'Tab1'] (active)>
Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKitCore/UIView.h> may also be helpful.
When I tap Here is Tab1 Tap me to NavigatedView
things goes well. However, when return to ContentView (by clickinig <Tab1
on left upper corner), I got another error info printed in the console:
Trying to pop to a missing destination at /Library/Caches/com.apple.xbs/Sources/Monoceros_Sim/Monoceros-120/Shared/NavigationBridge_PhoneTV.swift:341
English is not my native language; please excuse typing errors. Any advice will be helpful!
KOR
두 번째 화면에서 제어 센터를 통해 다크 모드 토글을 누를 경우 탭 화면으로 돌아갑니다.
ENG
On the second screen, when you press the Dark Mode toggle through Control Center, it returns to the tab screen.
iPhone 12 Mini
iOS 15.4
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.