【问题标题】:SWRevealViewController - How to elegantly make the menu disappear with a tap on FrontViewControllerSWRevealViewController - 如何优雅地通过点击 FrontViewController 使菜单消失
【发布时间】:2014-05-22 16:13:43
【问题描述】:
我希望在菜单可见时点击前视图控制器时隐藏菜单。
我需要知道一个优雅的解决方案,它不会让我在我的所有视图控制器上添加手势识别器
【问题讨论】:
标签:
ios
ipad
cocoa-touch
swrevealviewcontroller
【解决方案1】:
SWRevealViewController 为您提供了一个随时可用的点击手势控制器。所以你可以简单地将它添加到你的前端控制器:
self.view.addGestureRecognizer(self.revealViewController().tapGestureRecognizer())
另外,如果你只想做一次,你可以创建一个控制器来添加这个手势识别器,然后从这个类继承。 Swift 中的示例:
class YourFrontViewControllerParentClass : UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
if let revealController = self.revealViewController() {
// add the tap gesture recognizer to the front view (RootViewController) so that the sidebar menu closes when the user taps the front view when the side menu is closed.
self.view.addGestureRecognizer(self.revealViewController().tapGestureRecognizer())
}
}
}
class YourFrontViewControllerChildClass1 : YourFrontViewControllerParentClass {
override func viewDidLoad() {
super.viewDidLoad()
// specific stuff
}
}
class YourFrontViewControllerChildClass2 : YourFrontViewControllerParentClass {
override func viewDidLoad() {
super.viewDidLoad()
// specific stuff
}
}
class YourFrontViewControllerChildClass3: YourFrontViewControllerParentClass {
override func viewDidLoad() {
super.viewDidLoad()
// specific stuff
}
}