如何使SWRevealViewController菜单消失

如何使SWRevealViewController菜单消失

本文介绍了当用户点击视图控制器时,如何使SWRevealViewController菜单消失的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有带有嵌入式SWRevealViewController的View控制器,我在下面添加了代码以在使用菜单时禁用任何交互.

I have View controller with embedded SWRevealViewController I've added code below to disable any interaction while the menu on use.

viewcontroller嵌入了tableview.

The viewcontroller is embeded with tableview.

当用户点击视图控制器上的松弛应用程序时,如何使菜单消失:当使用菜单并点击聊天时,菜单消失"

  class Feed: UIViewController,SWRevealViewControllerDelegate {
@IBOutlet weak var menuButton:UIBarButtonItem!

@IBOutlet weak var menuButton:UIBarButtonItem!

override func viewDidLoad() {
    super.viewDidLoad()

    if self.revealViewController() != nil {
        menuButton.target = self.revealViewController()
        menuButton.action = "revealToggle:"
        self.revealViewController().delegate = self
        self.view.addGestureRecognizer(self.revealViewController().panGestureRecognizer())

    }

    fetchMessages()
}





func revealController(revealController: SWRevealViewController!, willMoveToPosition position: FrontViewPosition)
{
    if position == FrontViewPosition.Left     // if it not statisfy try this --> if revealController.frontViewPosition == FrontViewPosition.Left
    {
        self.view.userInteractionEnabled = true
    }
    else
    {
        self.view.userInteractionEnabled = false
    }

    func revealController(revealController: SWRevealViewController!, didMoveToPosition position: FrontViewPosition)
    {
        if position == FrontViewPosition.Left     // if it not statisfy try this --> if revealController.frontViewPosition == FrontViewPosition.Left
        {
            self.view.userInteractionEnabled = true
        }
        else
        {
            self.view.userInteractionEnabled = false
        }

    }
}

推荐答案

//在您的视图控制器类中设置委托

//set the delegate in your view controller class

class FeedVC: UIViewController,SWRevealViewControllerDelegate,UIGestureRecognizerDelegate


 override func viewDidLoad() {
    super.viewDidLoad()

  self.revealViewController().delegate = self
    var swl=self.revealViewController()


    if swl != nil
    {
        swl.panGestureRecognizer()
        swl.tapGestureRecognizer()
    }
}

//创建左栏按钮动作

@IBAction func but_back(sender: AnyObject) {

    self.navigationController?.interactivePopGestureRecognizer.delegate=self
    self.navigationItem.leftBarButtonItem?.target=self.revealViewController()
    self.navigationItem.leftBarButtonItem?.action=Selector("revealToggle:")
    self.revealViewController().revealToggle(sender)

    self.view.addGestureRecognizer(self.revealViewController().panGestureRecognizer())
}

//设置SWLReval的委托方法

//set the delegate method for SWLReval

func revealController(revealController: SWRevealViewController!, willMoveToPosition position: FrontViewPosition)
{
    if position == FrontViewPosition.Left     // if it not statisfy try this --> if revealController.frontViewPosition == FrontViewPosition.Left
    {
        self.view.userInteractionEnabled = true
        revealController.panGestureRecognizer().enabled=true
    }
    else
    {
        self.view.userInteractionEnabled = false
        revealController.panGestureRecognizer().enabled=false
    }



}

此链接中提供了更新的代码,请在此处下载该项目

the updated code is available in this link , download the project in here

这篇关于当用户点击视图控制器时,如何使SWRevealViewController菜单消失的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-30 23:39