John-Lluch / SWRevealViewController

A UIViewController subclass for presenting side view controllers inspired on the FaceBook and Wunderlist apps, done right !
Other
4.52k stars 987 forks source link

panGestureRecognizer with four Views and four ViewControllers in a Tab Bar Application #502

Closed poowl closed 9 years ago

poowl commented 9 years ago

Hello! I'm using the SWRevealViewController with four Views and four individual ViewControllers. On each View I got an icon at the navigation bar in the left corner and clicking on that icon is working on every View without problems. But the panGestureRecognizer is only working for the first time. If I'm at the first view and swipe, then it will work, but if I switch to the second view and than back to the first view, the swipe isn't working. I don't get any errors.

Could this be an issue with SWRevealViewController or rather with my programming?

iDevelopper commented 9 years ago

Where and how do you set the panGesture to your Navigation Bar?

poowl commented 9 years ago

At each of the four ViewControllers like this:

    self.view.addGestureRecognizer(self.revealViewController().panGestureRecognizer())
iDevelopper commented 9 years ago

self.revealViewController is not nil?

And d if you try this, what's happen? (objective-c: you have to adapt)

In viewDidLoad method:

    [self.navigationController.navigationBar addGestureRecognizer:self.revealViewController.panGestureRecognizer];
poowl commented 9 years ago

I know it's off topic, but are there some good guides or examples to "adapt" objective c in swift? At this time I actually don't know what to do. Thanks!

iDevelopper commented 9 years ago

At this time you can test replacing view by navigationController.navigationBar, no?

poowl commented 9 years ago

Ahhh okay, now I understand what you mean. But unfortunately your proposal isn't working. Now the panGestureRecognizer isn't working. I added a link to a zip of my project, maybe I did something wrong at another point?

https://drive.google.com/file/d/0B_DwuPXffCkrclRmSzZQLXViVW8/view?usp=sharing

iDevelopper commented 9 years ago
Gesture Recognizers Are Attached to a View
Every gesture recognizer is associated with one view. By contrast, a view can have multiple gesture recognizers, because a single view might respond to many different gestures. For a gesture recognizer to recognize touches that occur in a particular view, you must attach the gesture recognizer to that view. When a user touches that view, the gesture recognizer receives a message that a touch occurred before the view object does. As a result, the gesture recognizer can respond to touches on behalf of the view.

https://developer.apple.com/library/ios/documentation/EventHandling/Conceptual/EventHandlingiPhoneOS/GestureRecognizer_basics/GestureRecognizer_basics.html

So, for each view :

import UIKit

class FirstViewController: UIViewController {

    @IBOutlet weak var FirstButton: UIBarButtonItem!

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.

        FirstButton.target   =   self.revealViewController()
        FirstButton.action   =   Selector("revealToggle:")
    }

    override func viewWillAppear(animated: Bool) {
        super.viewWillAppear(animated)
        self.view.addGestureRecognizer(self.revealViewController().panGestureRecognizer())
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
}
poowl commented 9 years ago

Ahhh, okay that makes sense. Sorry, my fault, I should have read this info for myself. Thank you very much! No more issue here! Thanks!

iDevelopper commented 8 years ago

https://github.com/iDevelopper/PBRevealViewController