xcode 使用 SWRevealViewController ( ios) 时如何手动关闭侧边栏菜单

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/26555600/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 05:59:33  来源:igfitidea点击:

How to close the SideBar menu manually when using SWRevealViewController ( ios)

iosxcodeuialertviewsidebarswrevealviewcontroller

提问by moni_sind

I am trying to implement a SideBar/ slide out menu using the SWRevealViewController. I have a bunch of menus. One of the menu is to get app version info. So When I click on the cell, An AlertViewdisplays the version number and on pressing the OK button I would like to close/hide the SideBarmenu and return to the pervious view(front controller). For example, if I am on log in controller and I press the settings button to reveal the side bar and I choose version menu from TableViewcells, a pop will open displaying version# and when I press Ok, the SideBarshould close and return to the login screen without me having to tap the settings button again or swiping to return. How can I return to the login screen when I press OK on the alert view.

我正在尝试SideBar使用SWRevealViewController. 我有一堆菜单。菜单之一是获取应用程序版本信息。因此,当我单击单元格时,AnAlertView会显示版本号,然后按 OK 按钮,我想关闭/隐藏SideBar菜单并返回上一个视图(前控制器)。例如,如果我在登录控制器上并按下设置按钮以显示侧栏并从TableView单元格中选择版本菜单,则会弹出一个显示版本#的弹出窗口,当我按下确定时,SideBar应该关闭并返回登录我无需再次点击设置按钮或滑动即可返回。当我在警报视图上按 OK 时,如何返回登录屏幕。

- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex {
    // the user clicked OK
    if (buttonIndex == 0) {

      //close the side bar and return to front view controller
    }
}

回答by moni_sind

I just figured out the answer. I just use the following code to hide the side bar.

我刚刚想出了答案。我只是使用下面的代码来隐藏侧边栏。

- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex {
   if (buttonIndex == 0) {
    [self.revealViewController revealToggleAnimated:YES];

   }
}

回答by Nupur Sharma

The correct answer is:

正确答案是:

self.revealViewController().revealToggle(animated: true)

回答by Alap Anerao

If anyone is looking for a swiftversion, just use this single line:

如果有人正在寻找swift版本,只需使用这一行:

self.revealViewController().revealToggleAnimated()

回答by aqeel

if the sidebar on left using:

如果左侧的侧边栏使用:

    self.revealViewController().revealToggle(animated: true)

if was on the right using:

如果在右边使用:

    self.revealViewController().rightRevealToggle(animated: true)

回答by Sachin Daingade

//View Did load add this // Swift 4.2

//查看是否加载添加了这个 // Swift 4.2

func viewDidLoad() {

super.viewDidLoad()
let leftMenuItem = UIBarButtonItem(image: UIImage(named: "menu"), style: .plain, target: revealViewController, action: #selector(SWRevealViewController.revealToggle(_:)))
navigationItem.setLeftBarButton(leftMenuItem, animated: true)

}