ios – Including Habits to Transition Buttons in UISplitViewController for Totally 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 dimension:

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

For every of those circumstances, I need 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 principle view.

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

import UIKit

class ViewController: UIViewController {
    
    let splitVC = UISplitViewController(model: .doubleColumn)
    var hideBarButton: UIBarButtonItem!
    var showBarButton: UIBarButtonItem!
    
    var isExplorerHidden = false
    
    override func viewDidLoad() {
        tremendous.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.present(.major)
        
        splitVC.presentsWithGesture = false
        hideBarButton = UIBarButtonItem(
            picture: UIImage(systemName: "arrow.up.left.and.arrow.down.proper"),
            model: .plain,
            goal: self,
            motion: #selector(didTapHideBarButton))
        showBarButton = UIBarButtonItem(
            picture: UIImage(systemName: "sidebar.left"),
            model: .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
        splitVC.present(.secondary)
        splitVC.disguise(.major)
    }
    
    @objc func didTapShowBarButton() {
        hideBarButton.isHidden = false
        showBarButton.isHidden = true
        splitVC.present(.major)
        splitVC.disguise(.secondary)
    }
    
    personal 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
        updateHideAndShowButtonState()
    }
    
    func splitViewController(_ svc: UISplitViewController, willHide column: UISplitViewController.Column) {
        guard column.rawValue == 0 else { return }
        isExplorerHidden = true
        updateHideAndShowButtonState()
    }
}

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

https://github.com/Se1getsu/splitvc-test/blob/major/splitvc-test/ViewController.swift

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

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest Articles