swiftuitabbarcontrollerswrevealviewcontroller

Opening a side menu on click on a TAB bar in SWIFT


I want to make something like below snapshots.

When I click on profile tab bar instead of opening a new view controller it shows a side menu. Is it something that has been handled on click of tabbar ?

Image 1 Image 2


Solution

  • if you want to achieve something like your screenShot then you are using a wrong library, because when you show your right viewController the front viewController go to left by amount of width of your right viewController, but anyways here is the code for what you need to do

    first you need to put your viewController as delegate of your TabBarViewController and in func tabBarController(tabBarController: UITabBarController, shouldSelectViewController viewController: UIViewController) -> Bool you need to return false and call the method of SWRevealViewController to show right viewController rightRevealToggleAnimated(true)

    class FirstViewController: UIViewController,SWRevealViewControllerDelegate,UITabBarControllerDelegate {
    
        @IBOutlet weak var sliderControl: UISlider!
        override func viewDidLoad() {
            super.viewDidLoad()
            // Do any additional setup after loading the view, typically from a nib.
            self.revealViewController().delegate = self
            self.tabBarController?.delegate = self
        }
    
        override func viewWillAppear(animated: Bool) {
            super.viewWillAppear(animated)
            //self.view.removeGestureRecognizer(self.revealViewController().panGestureRecognizer())
            //self.view.addGestureRecognizer(self.revealViewController().panGestureRecognizer())
        }
    
        override func didReceiveMemoryWarning() {
            super.didReceiveMemoryWarning()
            // Dispose of any resources that can be recreated.
        }
    
    func tabBarController(tabBarController: UITabBarController, shouldSelectViewController viewController: UIViewController) -> Bool {
    
        //checking for specific viewController
        if(viewController is DesiredViewControllerClass) {
            self.revealViewController().rightRevealToggleAnimated(true)
        }
        return false
    }
    
    
    }
    

    I hope this helps you, regards