SWRevealViewController gestures not working
Hi I have an embedded swrevealview controller in swift mode.
I wrote below code in delegate app.
let frontView = ViewController(nibName: "ViewController", bundle: nil)
let rearView = LeftViewController(nibName : "LeftViewController", bundle :nil)
var frontNavigationController = UINavigationController(rootViewController: frontView)
var rearNavigationController = UINavigationController(rootViewController: rearView)
menuSlider = SWRevealViewController(rearViewController: rearNavigationController, frontViewController: frontNavigationController)
menuSlider?.delegate = self
let rightView = LeftViewController(nibName : "RightViewController", bundle :nil)
menuSlider?.rightViewController = rightView
self.window?.rootViewController = menuSlider
self.window?.backgroundColor = UIColor.whiteColor()
self.window?.makeKeyAndVisible()
In the front view, I wrote
var revealController:SWRevealViewController = self.revealViewController()
self.view.addGestureRecognizer(revealViewController().panGestureRecognizer())
self.view.addGestureRecognizer(revealViewController().tapGestureRecognizer())
as shown in the demo. I have seen many posts suggesting to add gesture in views.
I'm not sure what I am doing wrong. Please help me with the solution.
thank
source to share
One thing I can think of is when it comes to your code, you don't store strong references to front rearview controllers anywhere. It will basically be deallocated immediately after execution exits the method body. In your case, something like this will solve the problem:
Class myClass {
// Declaration
var frontNC : UINavigationController!
var rearNC : UINavigationController!
...
func myFunction() {
// Usage
self.frontNC = UINavigationController(rootViewController: frontView)
self.readNC = UINavigationController(rootViewController: rearView)
// Note* there is no need to store ViewControllers because those
// are retained by UINavigationController by default. The only
// exception is if you want to do something with them later obviously :)
}
}
As long as it is displayed, it creates a whole bunch of problems and gesture recognizers, which are the worst to track in my experience.
You can read more details on how ARC works in the Apple documentation , I don't think anyone can explain it better than what is written there :)
source to share