、、extension给原类,添加属性和方法
extension Selector {
static let toMenu = #selector(SWRevealViewController.revealToggle(_:))
static let toExtra = #selector(SWRevealViewController.rightRevealToggle(_:))
}
extension UIViewController {
func addSideBarMenu(_ leftBarButtonItem: UIBarButtonItem?, rightBarButtonItem: UIBarButtonItem? = nil) -> Void
{
if let revealVC = revealViewController() {
if let leftItem = leftBarButtonItem {
leftItem.target = revealVC
leftItem.action = Selector.toMenu
}
if let rightItem = rightBarButtonItem {
revealVC.rightViewRevealWidth = 150
rightItem.target = revealVC
rightItem.action = Selector.toExtra
}
view.addGestureRecognizer(revealVC.panGestureRecognizer())
}
}
}
、、开源lib
SWRevealViewController