HomeiOS Developmentios - Including Conduct to Transition Buttons in UISplitViewController for Completely different...

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 dimension:

(a) Aspect 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 displaying the primary view triggers a push transition (iPad multitasking/iPhone).

For every of those instances, 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 primary view.

I’ve been in a position to 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() {
        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(.main)
        
        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
        splitVC.present(.secondary)
        splitVC.conceal(.main)
    }
    
    @objc func didTapShowBarButton() {
        hideBarButton.isHidden = false
        showBarButton.isHidden = true
        splitVC.present(.main)
        splitVC.conceal(.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() {
        // Referred to as when the transition button is pressed.
        if splitVC.displayMode != .oneBesideSecondary {
            didTapHideBarButton()
        }
    }
}

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

Nevertheless, I am struggling to determine find out how to implement the conditional branching for (c). If anybody has any concepts or strategies, please let me know.

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments