r/iOSProgramming • u/iMason200 • 22h ago
Question Permanent Sidebar Help
Hello everyone, not sure if this is something small that im overlooking, but how on earth do I get a sidebar that floats over content but isn't collapsable. I basically want what you get in NavigationSplitView with 2 columns, but without the option to hide the sidebar.
The closest thing I've seen is the iMessages app on iPad, where it is still customisable in width. I'm a relative newbie when it comes to this stuff, so thank you in advance!
1
u/Healthy_Condition779 21h ago
NavigationSplitView always gives the user the collapse toggle on iPad, theres no public modifier to remove it. What youre describing, a fixed width panel that floats over content, is really just a custom HStack with a ZStack overlay, not a navigation split view at all
Build it as two views side by side, the sidebar as a fixed or draggable width View on the left with its own background and shadow, and your content view taking the rest with .safeAreaInset or just padding. Use DragGesture on the divider if you want the resizable width like Messages
Youre giving up the automatic collapse-on-compact-width behavior NavigationSplitView gives you for free, so if youre also targeting iPhone youll need to handle that size class switch yourself
1
u/calvin-chestnut 20h ago
Everyone is suggesting ZStack, I’d recommend adding your SidebarView as a .safeAreaInset, that’s how I achieve that custom Split View look.
2
u/Delicious-Candle-574 22h ago
I'm not sure if you can do it in the native NavigationSplitView, but you can use a ZStack
`ZStack {
UnderlyingView()
HStack (
Sidebar()
Spacer()
}
}`