[英]Hide TabBar when a new view is pushed in SwiftUI
how can I hide the TabBar when a new View is pushed via NavigationLink?当通过 NavigationLink 推送新视图时,如何隐藏 TabBar?
Here's how I push the next View:这是我推送下一个视图的方式:
TabView {
NavigationView {
List(fakeUser) { user in
NavigationLink(destination: ChatDetailView(user: user)) {
ChatCell(user: user)
}
}
.navigationBarTitle("Chats")
.navigationBarItems(leading: leadingBarItem, trailing: trailingBarItem)
}
.tabItem {
Image(systemName: "message.fill")
.font(.system(size: 20))
Text("Chats")
}
}
Caution: rise exception on Xcode 11.2/iOS 13.2注意:在 Xcode 11.2/iOS 13.2 上出现异常
Here is a relayout which gives an effect you requested, as far as I understood.据我了解,这是一个重新布局,可提供您要求的效果。
However, although there is nothing criminal in below code, on navigate back internals of UIKit got into exception:然而,虽然在下面的代码中没有犯罪,但在 UIKit 的内部导航返回异常:
2019-11-24 10:54:36.644037+0200 Test[1180:41920] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Tried to pop to a view controller that doesn't exist.' 2019-11-24 10:54:36.644037+0200 测试 [1180:41920] *** 由于未捕获的异常“NSInternalInconsistencyException”而终止应用程序,原因:“试图弹出到不存在的视图 controller。” *** First throw call stack: ( 0 CoreFoundation 0x00007fff23c4f02e __exceptionPreprocess + 350 1 libobjc.A.dylib 0x00007fff50b97b20 objc_exception_throw + 48 2 CoreFoundation 0x00007fff23c4eda8 +[NSException raise:format:arguments:] + 88 3 Foundation 0x00007fff256c9b61 -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 191 4 UIKitCore 0x00007fff4713d9d1 __57-[UINavigationController popToViewController:transition:]_block_invoke + 620 *** First throw call stack: ( 0 CoreFoundation 0x00007fff23c4f02e __exceptionPreprocess + 350 1 libobjc.A.dylib 0x00007fff50b97b20 objc_exception_throw + 48 2 CoreFoundation 0x00007fff23c4eda8 +[NSException raise:format:arguments:] + 88 3 Foundation 0x00007fff256c9b61 -[NSAssertionHandler handleFailureInMethod:object:文件:行号:描述:] + 191 4 UIKitCore 0x00007fff4713d9d1 __57-[UINavigationController popToViewController:transition:]_block_invoke + 620
Approach code方法代码
var body: some View {
NavigationView {
TabView {
List(fakeUser) { user in
NavigationLink(destination: ChatDetailView(user: user)) {
ChatCell(user: user)
}
}
.navigationBarTitle("Chats")
.navigationBarItems(leading: leadingBarItem, trailing: trailingBarItem)
.tabItem {
Image(systemName: "message.fill")
.font(.system(size: 20))
Text("Chats")
}
}
.navigationBarTitle("Chats")
}
}
In iOS 16 you have this option:在 iOS 16 中你有这个选项:
.toolbar(.hidden, for: .tabBar)
Just attach it to the view which is going to be pushed.只需将其附加到将要推送的视图即可。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.