我想创建一个汉堡包按钮。点击按钮它应该显示侧边栏菜单。但它不起作用。请帮帮我。
class HomeViewController:UIViewController,SWRevealViewControllerDelegate {
var button = UIButton()
var barButton = UIBarButtonItem()
override func viewDidLoad() {
super.viewDidLoad()
leftbarButton()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
func leftbarButton(){
button.setImage(UIImage(named: "hamburger"), for: .normal)
barButton = UIBarButtonItem(customView: button)
self.navigationItem.leftBarButtonItem = barButton
button.addTarget(self, action: #selector(menuAction(sender:)), for: .touchUpInside)
}
@objc func menuAction(sender:UIBarButtonItem){
barButton.target = self.revealViewController() barButton.action = #selector(SWRevealViewController.revealToggle(_:))
}
}