fahidattique55 / FAPanels

FAPanels - Swift
Apache License 2.0
851 stars 90 forks source link

FAPanel use from other viewcontroller #27

Closed JayeshPoriya closed 6 years ago

JayeshPoriya commented 6 years ago

Hi, This is not an issue, I need your help.
How can I use FAPanel from another view controller. I don't want to use FAPanel from appDelegate. I have Signin View Controller after successfully signin I want to use FAPanel. I already set root view controller is signin view controller. How can I use FAPanels after user signin? I want to use FAPanel in my signin view controller.

my view controller name is 1) LeftViewController 2) HomeViewController 3) not use right view controller so I passed nill

My Code is which is used in a signin view controller

                //====FAPanel for XIB
                let centerVC = HomeViewController(nibName: "HomeViewController", bundle: nil)
                let leftMenuVC = LeftViewController(nibName: "LeftViewController", bundle: nil)

               let centerNavVC = UINavigationController(rootViewController: centerVC)

                let window = UIWindow(frame: UIScreen.main.bounds)

// let appDelegate = UIApplication.shared.delegate as! AppDelegate

                let rootController: FAPanelController = window.rootViewController as! FAPanelController
                _ = rootController.center(centerNavVC).left(leftMenuVC).right(nil)
                window.makeKeyAndVisible()

But this code is not working.

Can you please help me!

I face this type of issue as well

Could not cast value of type 'UINavigationController' (0x10b719ed8) to 'appname.FAPanelController' (0x106fc41f8). 2018-03-09 16:05:07.504574+0530 appname[28149:682526] Could not cast value of type 'UINavigationController' (0x10b719ed8) to 'appname.FAPanelController' (0x106fc41f8).

fahidattique55 commented 6 years ago

@JayeshPoriya

No. 1

you can use FAPanels from a UIViewController but for that you need to understand working of FAPanels.

Working

  1. Create your controllers (Centre, Left and Right)
  2. Create a new FAPanel controller and assign the above controllers to it
  3. Set the newly created FAPanels controller as your root window controller

Here is how it should be implemented

Create the controllers required

In your signin view controller, Add these :

let leftMenuVC = LeftViewController(nibName: "LeftViewController", bundle: nil) let centerVC = HomeViewController(nibName: "HomeViewController", bundle: nil) let centerNavVC = UINavigationController(rootViewController: centerVC)

Create the FAPanels controller

let panelVC = FAPanelController()

Set newly created FAPanels controller as the root window controller

_ = panelVC.center(centerNavVC) UIApplication.shared.keyWindow?.rootViewController = panelVC

For animating the change from Sign in controller to your new home controller, Add the above two lines in a transition block like below,

UIView.transition(from: self.view, to: centerVC.view, duration: 0.5, options: UIViewAnimationOptions.transitionCrossDissolve) { (finished) in _ = panelVC.center(centerNavVC) UIApplication.shared.keyWindow?.rootViewController = panelVC }

fahidattique55 commented 6 years ago

Please let me know in case you need any further help. Thanks for using FAPanels 👍

Hamza-Brainplow commented 6 years ago

Hi, i'm trying to use FAPanels. i have installed pods and in my root view controller given it class to FAPanelController, and written the code in app delegate as u have said but getting this error "Use of undeclared type 'FAPanelController'".How i can fix this? Another thing is that how can i access the same panel from another view controller? Is this panel will run fine if i want LeftMenu and tab bar in my application?

fahidattique55 commented 6 years ago

No.1

Import the FAPanles framework in your app delegate class.

No.2

You can simply access by panel property of any UIViewController.

i.e : self.panel

JayeshPoriya commented 6 years ago

@fahidattique55 Thank you for replay! Now it's working.

jerrychong25 commented 5 years ago

let panelVC = FAPanelController()

Thanks! This is useful.