How to Disable the Show Tab Bar Menu Option in Swiftui

How do I disable the Show Tab Bar menu option in SwiftUI

I was looking for an answer for this as well and found out the following:

by default - as you already mentioned - the Show/Hide Tab is active:

Sample Image

There is a property on NSWindow called tabbingMode which allows us to take control by setting it to .disallowed. My problem though was: in a SwiftUI 2-lifecycle app, how can I get hold of the windows of the app?

Well, there's NSApplication.shared.windows, so my first (non working!!) attempt was to modify all the windows in my @main-App struct (as I already prevented new windows from being created, that should be suffice):

import SwiftUI

@main
struct DQ_SyslogApp: App {
var body: some Scene {
WindowGroup {
ContentView()
.onAppear {
let _ = NSApplication.shared.windows.map { $0.tabbingMode = .disallowed }
}
}
.commands {
CommandGroup(replacing: .newItem) {} //remove "New Item"-menu entry
}
}
}

Unfortunately this did not work as NSApplication.shared.windows is empty in .onAppear.

My next step involved introducing an AppDelegate to my SwiftUI 2-lifecycle that implements applicationDidFinishLaunching(_:)...

class AppDelegate: NSObject, NSApplicationDelegate {

func applicationDidFinishLaunching(_ notification: Notification) {
print("Info from `applicationDidFinishLaunching(_:): Finished launching…")
let _ = NSApplication.shared.windows.map { $0.tabbingMode = .disallowed }
}
}

...and introducing this AppDelegate to the app:

import SwiftUI

@main
struct DQ_SyslogApp: App {
@NSApplicationDelegateAdaptor(AppDelegate.self) var appDelegate

var body: some Scene {
WindowGroup {
ContentView()
}
.commands {
CommandGroup(replacing: .newItem) {} //remove "New Item"-menu entry
}
}
}

This did the trick for me:

Sample Image

While I would prefer to have the menu entries removed entirely, this at least prevents the user from having tabs which is what the OP was asking for.

If anybody should happen to know a solution to hide those entries, please let us know. I couldn't find a CommandGroupPlacement that represents these menus...

How do I disable the Show Tab Bar menu option in Sierra apps?

On 10.12, you need to now set the following when the window is created as Tab Bar is now available by default:

[NSWindow setAllowsAutomaticWindowTabbing: NO];

The answer is the same in Swift and SwiftUI

func applicationWillFinishLaunching(_ notification: Notification) {
NSWindow.allowsAutomaticWindowTabbing = false
}

Note that the call is made on the class NSWindow not on an instance of NSWindow

Remove 'Show/Hide tab bar' menu item

In Interface Builder, open the attributes of your NSWindow and you'll see an option called "Tabbing Mode". Set it to Disallowed.

SwiftUI: How to ignore taps on background when menu is open?

You can implement an .overlay which is tappable and appears when you tap on the menu.
Make it cover the whole screen, it gets ignored by the Menu.
When tapping on the menu icon you can set a propertie to true.
When tapping on the overlay or a menu item, set it back to false.

You can use place it in your root view and use a viewmodel with @Environment to access it from everywhere.

The only downside is, that you need to place isMenuOpen = false in every menu button.

Apple is using the unexpected behaviour itself, a.ex in the Wether app.
However, I still think it's a bug and filed a report. (FB10033181)

Sample Image

@State var isMenuOpen: Bool = false

var body: some View {
NavigationView{
NavigationLink{
ChildView()
} label: {
Text("Some NavigationLink")
.padding()
}
.toolbar{
ToolbarItem(placement: .navigationBarTrailing){
Menu{
Button{
isMenuOpen = false
} label: {
Text("Some Action")
}
} label: {
Image(systemName: "ellipsis.circle")
}
.onTapGesture {
isMenuOpen = true
}
}
}
}
.overlay{
if isMenuOpen {
Color.white.opacity(0.001)
.ignoresSafeArea()
.frame(maxWidth: .infinity, maxHeight: .infinity)
.onTapGesture {
isMenuOpen = false
}
}
}
}

Disable Edit Button that appear in more selection of tab bar ios

You had to say that none of your view controllers is customizable. Then the edit button disappears. Please look up the docs.

tabBarController.customizableViewControllers = @[];  

Docs: "This property controls which items in the tab bar can be rearranged by the user. When the user taps the More item on the tab bar view, a custom interface appears displaying any items that did not fit on the main tab bar. This interface also contains an Edit button that allows the user to rearrange the items. Only the items whose associated view controllers are in this array can be rearranged from this interface. If the array is empty or the value of this property is nil, the tab bar does not allow any items to be rearranged."

Hiding tab bar on a specific page in SwiftUI

I updated my solution with TabView for your situation. The same idea: you're using ZStack and @State var selection. And the idea is to use .opacity of TabView and YourCameraView (which is just Image(systemName: "plus.circle") in my example):

struct TabViewModel: View {

@State var selection: Int = 0

var body: some View {

ZStack {
GeometryReader { geometry in
TabView(selection: self.$selection) {

Text("list")
.tabItem {
Image(systemName: "list.bullet.below.rectangle")
}.tag(0)

Text("plus")
.tabItem {
Image(systemName: "camera")
}.tag(1)

Text("more categories!")
.tabItem {
Image(systemName: "square.grid.2x2")
}.tag(2)
}
.opacity(self.selection == 1 ? 0.01 : 1)

Image(systemName: "plus.circle")
.resizable()
.frame(width: 60, height: 60)
.shadow(color: .gray, radius: 2, x: 0, y: 5)
.offset(x: geometry.size.width / 2 - 30, y: geometry.size.height - 80)
.onTapGesture {
self.selection = 0
}
.opacity(self.selection == 1 ? 1 : 0)
}

}

}
}

when you tap on camera tabItem TabView becomes invisible

Hide tab bar in IOS swift app

You can simply use this in your ViewDidLoad() method.

self.tabBarController?.tabBar.hidden = true

For Swift 3.0, 4.0, 5.0:

self.tabBarController?.tabBar.isHidden = true

Or you can change z position of tab bar this way:

self.tabBarController?.tabBar.layer.zPosition = -1

and if you want to show it again then:

self.tabBarController?.tabBar.layer.zPosition = 0


Related Topics



Leave a reply



Submit