3

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

Sam
  • 452
  • 5
  • 15

2 Answers2

4

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

Reinier Melian
  • 20,519
  • 3
  • 38
  • 55
  • Thanks for the reply but what I want to achieve is that when I click on "PROFILE" button, instead of going on profileviewcontroller it should show this menu. It is like profile tab will just act as a button which calls the menu out but the focus on first view controller will not shift. – Sam Jun 29 '16 at 14:54
  • you need to show right menu instead of button action? is that what you want to achieve? – Reinier Melian Jun 29 '16 at 15:01
  • I want the profile tab to be there but the right menu should come on its click and no change should be made on TabViewController. Suppose I am currently on first tab that is Listing and I click on the fifth tab (profile). So, in normal cases the focus will shift to profile tab but in my case I want the right menu to come and the focus should remain on the first tab. – Sam Jun 29 '16 at 15:05
  • You are using a UITabBarViewController or just a TabBar? – Reinier Melian Jun 29 '16 at 15:08
  • I am using a UITabBarController and then adding various view controller to it. – Sam Jun 29 '16 at 15:11
  • 1
    my answer was edited @Sam you need to implement this method `func tabBarController(tabBarController: UITabBarController, shouldSelectViewController viewController: UIViewController) -> Bool` instead, this will keep in currentViewController and show the right menu, regards. I hope this helps you – Reinier Melian Jun 29 '16 at 15:16
  • 1
    Thanks a ton! you are awesome :) – Sam Jun 29 '16 at 15:18
  • 1
    Thanks, everything is working fine but when I call reveal view controller in this call self.revealViewController().rightRevealToggleAnimated(true); it shifts my screen by the amount of width od reveal view controller. Is there any solution to this ? – Sam Jul 28 '16 at 17:53
  • 1
    how would you set up the storyboard for this? @Reinier Melian – Cesar Mtz Aug 03 '16 at 05:40
  • @ReinierMelian But, how to know which tab we are showing the menu for me it is showing menu when I click any of the tabs.. – Venkatesh Chejarla Nov 19 '18 at 11:33
  • you can check viewController class type, and react accordingly hope this helps you @VenkateshChejarla – Reinier Melian Nov 19 '18 at 11:36
  • @ReinierMelian Thanks for the immediate response.. I tried `if viewController == menuNavigationController() { self.revealViewController().revealToggle(animated: true) }`, but nothings happens. I would be so thankful, if you could update the code or you could just comment.. Thanks. – Venkatesh Chejarla Nov 19 '18 at 11:47
  • @VenkateshChejarla you need to check for type, dont for object, I mean if your menuNavigationController class is `MenuNavigationController` you need to check `if(viewController is MenuNavigationController) { //your code here}` check my answer was updated anyway – Reinier Melian Nov 19 '18 at 11:55
  • Glad to help you @VenkateshChejarla happy coding! – Reinier Melian Nov 19 '18 at 12:08
1

You can use the tab bar delegate:

extension ViewController: UITabBarDelegate {
    func tabBar(tabBar: UITabBar, didSelectItem item: UITabBarItem) {
        // Present hamburger menu
    }
}
jimmyy
  • 139
  • 3