Skip to content

kyleYang/KYFlipNavigationController

Repository files navigation

KYFlipNavigationController

CI Status Version License Platform

The KYFlipNavigationController is an custom NavigationController the use UIViewController to manager the UIViewController(include UINavigationController,UITabbarController,UIViewController) like the UINavigationController . Many app like EasyNet News and Toutiao use TabbarController UINavigationController when push

##Overview alt tag

Usage

To run the example project, clone the repo, and run pod install from the Example directory first.

Init

Set up flipNavigationController as root of a window,self.flipNavigationController will find the KYFlipNavigationController if it's exist!

   let firstVC = FirstViewController(nibName: nil, bundle: nil);
   firstVC.title = "First"
   let firstNavi = UINavigationController(rootViewController: firstVC)

   let sencondVC = SecondViewController(nibName: nil, bundle: nil);
   sencondVC.title = "Second"

   let tabbar = RDVTabBarController()
   tabbar.viewControllers = [firstNavi,sencondVC]
   
   let flipViewController = KYFlipNavigationController(rootViewCotroller: tabbar)
   self.window = UIWindow();
   self.window?.backgroundColor = UIColor.white;
   self.window?.rootViewController = flipViewController;
   self.window?.makeKeyAndVisible()

Push or Pop

Push and pop almost like the UINavigationController . The key way is to find the flipNavigationController. It's easy that we use a UIViewController's extension

   //Push
   let  viewController = ThirdViewController(nibName: nil, bundle: nil)
   viewController.title = "cell_\(indexPath.row)"
   // push a navigationcontroller
   let navi = UINavigationController(rootViewController: viewController)
   self.rdv_tabBarController.flipNavigationController?.pushViewController(navi, animated: true)//self is add to a tabbarcontroller
   
   //we also an push a UIViewController,and if self is not add to a tabbarcontroller
   self.flipNavigationController?.pushViewController(viewController, animated: true)
   

     //Pop
    self.flipNavigationController?.popViewController(true)
    //also we can pop to a viewcontroller or to the rootviewcontroller

The public func

   //Push
   pushViewController(_ viewController : UIViewController, animated : Bool, completed : KYFlipNavigationCompletionBlock? = nil)

   //Pop
   public func popViewController(_ animated : Bool, completed : KYFlipNavigationCompletionBlock? = nil)
   public func popToViewController(_ viewController : UIViewController, animated : Bool, completed : KYFlipNavigationCompletionBlock? = nil)
   public func popToRootViewControllerAnimated(_ animated : Bool ,completed : KYFlipNavigationCompletionBlock?)

Change the stack

You can also change the UIViewController stack when you want,so you can remove some viewcontroller or add some viewcontroller from the stack and change the pop way

    guard let viewControllers = self.flipNavigationController?.viewControllers else {
    	return
    }
    var newControllers : Array<UIViewController> = []
    for viewController in viewControllers {
       if !viewController.isKindOfClass(ForthViewController.self) {
            newControllers.append(viewController)
        }
    }
    self.flipNavigationController?.viewControllers = newControllers

Requirements

Installation

KYFlipNavigationController is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod "KYFlipNavigationController"

Author

kyleYang, yangzychina@gmail.com

If you find any porblem , please tell me

License

KYFlipNavigationController is available under the MIT license. See the LICENSE file for more info.

About

A Custom Push Navigation Controller

Resources

License

Stars

Watchers

Forks

Packages

No packages published