logic to work on small phones
This commit is contained in:
parent
0b150e8945
commit
5c2901fbfa
@ -13,6 +13,10 @@ import MVMCoreUI
|
|||||||
class AppDelegate: UIResponder, UIApplicationDelegate, UISplitViewControllerDelegate {
|
class AppDelegate: UIResponder, UIApplicationDelegate, UISplitViewControllerDelegate {
|
||||||
|
|
||||||
var window: UIWindow?
|
var window: UIWindow?
|
||||||
|
var mvcNav: UINavigationController?
|
||||||
|
var dvcNav: UINavigationController?
|
||||||
|
var mvc: UIViewController?
|
||||||
|
var dvc: UIViewController?
|
||||||
|
|
||||||
func application(_ application: UIApplication, willFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool {
|
func application(_ application: UIApplication, willFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool {
|
||||||
// Setup our core object with the default implementation
|
// Setup our core object with the default implementation
|
||||||
@ -24,10 +28,26 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UISplitViewControllerDele
|
|||||||
|
|
||||||
// Override point for customization after application launch.
|
// Override point for customization after application launch.
|
||||||
let splitViewController = window!.rootViewController as! UISplitViewController
|
let splitViewController = window!.rootViewController as! UISplitViewController
|
||||||
let navigationController = splitViewController.viewControllers[splitViewController.viewControllers.count-1] as! UINavigationController
|
mvcNav = splitViewController.viewControllers[0] as? UINavigationController
|
||||||
navigationController.topViewController!.navigationItem.leftBarButtonItem = splitViewController.displayModeButtonItem
|
mvcNav?.delegate = self
|
||||||
|
mvc = mvcNav?.topViewController
|
||||||
|
dvcNav = splitViewController.viewControllers[splitViewController.viewControllers.count-1] as? UINavigationController
|
||||||
|
dvc = dvcNav?.topViewController
|
||||||
|
dvc?.navigationItem.leftBarButtonItem = splitViewController.displayModeButtonItem
|
||||||
|
dvc?.navigationItem.leftItemsSupplementBackButton = true
|
||||||
splitViewController.delegate = self
|
splitViewController.delegate = self
|
||||||
splitViewController.preferredDisplayMode = .allVisible
|
splitViewController.preferredDisplayMode = .allVisible
|
||||||
|
|
||||||
|
NotificationCenter.default.addObserver(forName: UIViewController.showDetailTargetDidChangeNotification, object: splitViewController, queue: nil) { [weak self] (notification) in
|
||||||
|
if let strongSelf = self, let svc = notification.object as? UISplitViewController {
|
||||||
|
if svc.isCollapsed {
|
||||||
|
strongSelf.mvc?.navigationItem.rightBarButtonItem = UIBarButtonItem(title: "Editor", style: .plain, target: self, action: #selector(self?.showEditor))
|
||||||
|
} else {
|
||||||
|
strongSelf.mvcNav?.setViewControllers([strongSelf.mvc!], animated: false)
|
||||||
|
strongSelf.mvc?.navigationItem.rightBarButtonItem = nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -55,12 +75,22 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UISplitViewControllerDele
|
|||||||
|
|
||||||
// MARK: - Split view
|
// MARK: - Split view
|
||||||
|
|
||||||
/*func splitViewController(_ splitViewController: UISplitViewController, collapseSecondary secondaryViewController:UIViewController, onto primaryViewController:UIViewController) -> Bool {
|
func splitViewController(_ splitViewController: UISplitViewController, collapseSecondary secondaryViewController:UIViewController, onto primaryViewController:UIViewController) -> Bool {
|
||||||
// guard let secondaryAsNavController = secondaryViewController as? UINavigationController else { return false }
|
//guard let secondaryAsNavController = secondaryViewController as? UINavigationController else { return false }
|
||||||
// guard let _ = secondaryAsNavController.topViewController as? DetailViewController else { return false }
|
//guard let _ = secondaryAsNavController.topViewController as? DetailViewController else { return false }
|
||||||
// return false
|
|
||||||
return true
|
return true
|
||||||
}*/
|
}
|
||||||
|
|
||||||
|
@objc func showEditor() {
|
||||||
|
mvcNav?.pushViewController(dvc!, animated: true)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
extension AppDelegate: UINavigationControllerDelegate {
|
||||||
|
func navigationController(_ navigationController: UINavigationController, didShow viewController: UIViewController, animated: Bool) {
|
||||||
|
if mvc == viewController {
|
||||||
|
dvcNav?.setViewControllers([dvc!], animated: false)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user