How it works
TabBarMinimizeBehavior describes when a TabView's tab bar should collapse into a compact form to yield screen space to the content beneath it. It gives you a small, type-safe vocabulary of policies — such as minimizing as the user scrolls down — that you hand to the tabBarMinimizeBehavior(_:) modifier rather than tracking scroll offsets and animating the bar yourself. Reach for it when a scroll-heavy tab should let its content take over the screen while keeping the tab bar one gesture away, the way Apple's own apps shrink the bar as you read and restore it when you scroll back.
Apply the behavior with tabBarMinimizeBehavior(_:)
TabBarMinimizeBehavior takes effect through the tabBarMinimizeBehavior(_:) modifier, which you attach to the TabView (or a view that contains it). The modifier reads the value and configures how the system manages the tab bar's collapsed and expanded states. In the example,
.tabBarMinimizeBehavior(.onScrollDown)is placed directly on theTabView, so the policy governs every tab it presents.Choose a policy with the type's static members
You rarely construct a TabBarMinimizeBehavior directly; instead you select one of its predefined values, written in leading-dot form because the modifier's parameter is already typed. The example passes
.onScrollDown, which tells SwiftUI to minimize the bar while the user scrolls down through content and bring it back as they scroll up — automatic state that you'd otherwise have to drive by hand.Give the behavior something to scroll
A scroll-driven policy like
.onScrollDownonly changes anything when a tab actually scrolls, so the symbol pairs naturally with scrolling content. Here theHomeTabwraps aScrollView, and as that view scrolls the tab bar minimizes; theSearchtab holds only a staticText, so within it there is nothing for the behavior to react to.Inherit across the tabs of one TabView
Because the modifier is applied to the
TabViewitself rather than to an individualTab, the chosen TabBarMinimizeBehavior is the bar's policy for the whole tab interface. TheHomeandSearchtabs share the same minimize behavior, so switching tabs doesn't reset or re-specify it.
.tabBarMinimizeBehavior(.onScrollDown) to .tabBarMinimizeBehavior(.automatic) (or remove the modifier entirely) and scroll the Home tab to watch the tab bar stay fixed instead of collapsing.Example & preview
Press Run live & edit to compile it in your browser — then edit the Swift on the left and the preview re-renders live.
struct TabBarMinimizeBehaviorDemo: View {
var body: some View {
TabView {
Tab("Home", systemImage: "house") {
ScrollView {
ForEach(1..<30) { i in
Text("Row \(i)")
.frame(maxWidth: .infinity, alignment: .leading)
.padding()
}
}
}
Tab("Search", systemImage: "magnifyingglass") {
Text("Search")
}
}
.tabBarMinimizeBehavior(.onScrollDown)
}
}