如何让SWRevealViewController覆盖主视图不推送呢?

How to make SWRevealViewController cover the main view not push it?

我正在学习本教程Customize your SWRevealViewController slide-out menu

这是 SWReveal 如何推送主视图的应用程序布局

但是 Gmail 的工作方式是像这张照片一样覆盖主视图

我想知道我是否可以使用 SWRevealViewController 使 silde-out 菜单像 Gmail 应用程序一样覆盖主视图以及如何做到这一点?

假设只剩下 left-menu 部分并且菜单在单击按钮时滑动。

按照以下步骤操作:

  1. 在你的 storyboard 中加入新的 UIViewController
  2. 这样做 a) 添加大小为 UIViewController 的新 UIView(表示 viewBG)。 b) 现在转到 属性 并根据您的需要降低 viewBG 不透明度,不要玩 alpha 值。 c) 再看一下左侧菜单(说 viewMenu)。

  3. 将您的 menuVC 添加为 MainVC 的 child VC。

  4. 现在当你想显示菜单时使用下面的行代码。

menuVC.view.frame = CGRect(x : -self.view.frame.size.width, y : 0, width : menuVC.view.frame.size.width, height: self.view.frame.size.height) UIView.animate(withDuration: 0.5) { menuVC.view.frame = CGRect(x : 0, y : 0, width : menuVC.view.frame.size.width, height: self.view.frame.size.height) }

  1. 删除菜单

menuVC.view.frame = CGRect(x : 0, y : 0, width : menuVC.view.frame.size.width, height: self.view.frame.size.height) UIView.animate(withDuration: 0.5) { menuVC.view.frame = CGRect(x : -self.view.frame.size.width, y : 0, width : menuVC.view.frame.size.width, height: self.view.frame.size.height) }

希望:您可以对您的视图进行限制。

我的问题的正确答案是打开这个问题: How to make SWRevealViewController works like covering the main view not as default pushing the main view ? #669

方法是将 "main" 视图控制器设置为 rearViewController(静态,不移动),将 "side Bar" 设置为 frontViewController(在顶部滑动,可选透明)。根据我对你想要实现的目标的理解,这就是你所需要的。