How to hide tabbar in subview #330
-
I am working with SwiftUI, and I have some issues with the TabBar. I want to hide the TabBar on a specific subview. I find some code in https://stackoverflow.com/questions/58444689/swiftui-hide-tabbar-in-subview. struct SomeView: View{
@State var uiTabarController: UITabBarController?
var body: some View {
List {
-your code here-
}
.navigationBarTitle("Title", displayMode: .inline)
.introspectTabBarController { (UITabBarController) in
UITabBarController.tabBar.isHidden = true
uiTabarController = UITabBarController
}.onDisappear{
uiTabarController?.tabBar.isHidden = false
}
}
} But I can not find introspectTabBarController method in the newest code. How can I use the new API to hide tabbar in sub view |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
By default, import SwiftUI
import SwiftUIIntrospect
@propertyWrapper
final class Weak<T: AnyObject> {
private weak var _wrappedValue: T?
var wrappedValue: T? {
get { _wrappedValue }
set { _wrappedValue = newValue }
}
init(wrappedValue: T? = nil) {
self._wrappedValue = wrappedValue
}
}
struct SomeView: View {
@Weak var tabBarController: UITabBarController?
var body: some View {
List {
// your code here
}
.navigationBarTitle("Title", displayMode: .inline)
.introspect(.tabView, on: .iOS(.v13, .v14, .v15, .v16, .v17), scope: .ancestor) { tabBarController in
tabBarController.tabBar.isHidden = true
self.tabBarController = tabBarController
}.onDisappear{
self.tabBarController?.tabBar.isHidden = false
}
}
} Note also the introduction of |
Beta Was this translation helpful? Give feedback.
By default,
.introspect
works directly on its receiver. This means calling.introspect
from inside the view you're trying to introspect won't have any effect. This is different to the original Introspect module in which some views would implicitly allow introspection from within. You can introspect an ancestor with SwiftUIIntrospect, but you must opt into this explicitly by overriding the introspection scope: