单击SWIFT中的TAB栏打开侧边菜单

时间:2016-06-25 19:55:10

标签: swift uitabbarcontroller swrevealviewcontroller

我想制作类似于快照的内容。

当我单击配置文件选项卡栏而不是打开新的视图控制器时,它会显示侧面菜单。这是单击tabbar时处理的内容吗?

Image 1 Image 2

2 个答案:

答案 0 :(得分:4)

如果您想要实现类似于screenShot的内容,那么您使用的是错误的库,因为当您显示正确的viewController时,前方viewController会向前移动右侧宽度viewController 1}},但无论如何这里是你需要做的代码

首先你需要把你的viewController作为你的TabBarViewController的委托,并在func tabBarController(tabBarController: UITabBarController, shouldSelectViewController viewController: UIViewController) -> Bool你需要返回false并调用SWRevealViewController的方法来显示正确的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
}


}

我希望这可以帮助你,问候

答案 1 :(得分:0)

您可以使用标签栏代理:

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