首先我们将检查 IOS 16 工具栏视图修改器解决方案,这看起来有点错误,我们将使我们的修改器符合 IOS 16版本之前的要求。
让我们首先开始IOS 16解决方案。
.toolbar(.visible, for: .tabBar)
我们视图的修饰符。
为了能够轻松使用
extension View {
@ViewBuilder func `if`(_ condition: Bool, transform: (Self) -> Content) -> some View {
if condition {
transform(self)
} else {
self
}
}
}
添加if修饰符到视图扩展。
然后将isTabbarHidden属性添加到 SecondCoordinator
@Published var isTabbarHidden: Bool
最后使用新的if修饰符将工具栏修饰符添加到视图中,并且不要忘记添加以设置coordinator.isTabbarHidden = false onDissappear。
struct SecondCoordinatorView: View {
// MARK: Stored Properties
@ObservedObject var coordinator: SecondCoordinator
// MARK: Views
var body: some View {
SecondView(viewModel: coordinator.viewModel)
.i