如何在IBAction方法中添加按钮目标功能

时间:2019-02-26 09:58:19

标签: swift swrevealviewcontroller uiswipegesturerecognizer

我将SWRevealViewController用于侧面菜单。当我单击menuBtn时,我正在执行右切换操作。当我向右滑动时,我也希望得到同样的声音。有人可以帮忙吗?

class Invoice: UIViewController {

@IBOutlet weak var menuBtn: UIButton!


override func viewDidLoad() {
        super.viewDidLoad()
        let revealViewController = self.revealViewController()
        menuBtn.addTarget(revealViewController, action: #selector(SWRevealViewController.rightRevealToggle(_:)), for: .touchUpInside)

}
@IBAction func swipeGesture(_ sender: UISwipeGestureRecognizer) {
        print("Swiped")
        //I want same action as i clicked on mentBtn
    }
}

1 个答案:

答案 0 :(得分:1)

类似的事情应该起作用:

@IBAction func swipeGesture(_ sender: UISwipeGestureRecognizer) {
    self.revealViewController().rightRevealToggle(self.menuBtn)
}