简体   繁体   English

SWRevealViewController滑动/点击手势无法正常工作

[英]SWRevealViewController Swipe/Tap gesture not working properly

I've implemented SWRevealViewController according to the tutorials I've seen for a hamburger slide menu. 我根据我在汉堡包幻灯片菜单中看到的教程实现了SWRevealViewController Things are working great, except if I use the slide menu on a later page in the app, and then collapse it, and then go to an earlier page and try to use it, it will open, but no gestures will collapse it unless I navigate back to the page that last opened the menu. 事情很有效,除非我在应用程序的后续页面上使用幻灯片菜单,然后将其折叠,然后转到较早的页面并尝试使用它,它将打开,但除非我没有手势会崩溃它导航回上次打开菜单的页面。 Then I can close it from there. 然后我可以从那里关闭它。

The code I'm using in the viewDidLoad of each ViewController is 我在每个ViewControllerviewDidLoad中使用的代码是

let menuButton = self.navigationItem.rightBarButtonItem
    if self.revealViewController() != nil {
        menuButton?.target = self.revealViewController()
        menuButton?.action = "revealToggle:"
        self.view.addGestureRecognizer(self.revealViewController().panGestureRecognizer())
        self.view.addGestureRecognizer(self.revealViewController().tapGestureRecognizer())

    }

Any ideas what's causing this/how to fix it? 是什么导致了这个/如何解决它?

Remove the code from ViewDidLoad and use it in ViewDidAppear . ViewDidLoad删除代码并在ViewDidAppear使用它。

ViewDidLoad runs only once, when UIViewController class is loading. 当加载UIViewController类时, ViewDidLoad只运行一次。

ViewDidAppear runs every time the UIViewController appears on screen. ViewDidAppear UIViewController出现在屏幕上时, ViewDidAppear运行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM