ios – Including Conduct to Transition Buttons in UISplitViewController for Completely different Show Modes


I am planning to make use of UISplitViewController to implement a facet menu. The preliminary show format of the UISplitViewController varies relying on the display screen dimension:

(a) Facet menu and primary view displayed facet by facet (iPad panorama mode).
(b) Solely the primary view is proven, and the facet menu overlaps the primary view when proven (iPad portrait mode).
(c) Solely the facet menu is displayed, and exhibiting the primary view triggers a push transition (iPad multitasking/iPhone).

For every of those circumstances, I wish to add particular behaviors to the transition buttons displayed within the facet menu:

(a) Do nothing.
(b) Shut the facet menu.
(c) Transition to the primary view.

I’ve been capable of obtain (a) and (b) utilizing the next code:

import UIKit

class ViewController: UIViewController {
    let splitVC = UISplitViewController(fashion: .doubleColumn)
    var hideBarButton: UIBarButtonItem!
    var showBarButton: UIBarButtonItem!
    var isExplorerHidden = false
    override func viewDidLoad() {
        let menuVC = MenuViewController()
        let mainVC = UIViewController()
        menuVC.view.backgroundColor = .systemBrown
        mainVC.view.backgroundColor = .systemMint
        splitVC.viewControllers = [
            UINavigationController(rootViewController: menuVC),
            UINavigationController(rootViewController: mainVC)
        splitVC.modalPresentationStyle = .fullScreen
        current(splitVC, animated: false)
        splitVC.presentsWithGesture = false
        hideBarButton = UIBarButtonItem(
            picture: UIImage(systemName: "arrow.up.left.and.arrow.down.proper"),
            fashion: .plain,
            goal: self,
            motion: #selector(didTapHideBarButton))
        showBarButton = UIBarButtonItem(
            picture: UIImage(systemName: "sidebar.left"),
            fashion: .plain,
            goal: self,
            motion: #selector(didTapShowBarButton))
        mainVC.navigationItem.leftBarButtonItems = [hideBarButton, showBarButton]
        for barButtonItem in mainVC.navigationItem.leftBarButtonItems! {
            barButtonItem.tintColor = .black
        showBarButton.isHidden = true
        menuVC.delegate = self
        splitVC.delegate = self
    @objc func didTapHideBarButton() {
        hideBarButton.isHidden = true
        showBarButton.isHidden = false
    @objc func didTapShowBarButton() {
        hideBarButton.isHidden = false
        showBarButton.isHidden = true
    non-public func updateHideAndShowButtonState() {
        hideBarButton.isHidden = isExplorerHidden
        showBarButton.isHidden = !isExplorerHidden


extension ViewController: UISplitViewControllerDelegate {
    func splitViewController(_ svc: UISplitViewController, willShow column: UISplitViewController.Column) {
        guard column.rawValue == 0 else { return }
        isExplorerHidden = false
    func splitViewController(_ svc: UISplitViewController, willHide column: UISplitViewController.Column) {
        guard column.rawValue == 0 else { return }
        isExplorerHidden = true

extension ViewController: MenuViewControllerDelegate {
    func hideMenu() {
        // Known as when the transition button is pressed.
        if splitVC.displayMode != .oneBesideSecondary {

Nonetheless, I am struggling to determine tips on how to implement the conditional branching for (c). If anybody has any concepts or ideas, please let me know.