-1

Does the Facebook mobile app use UISwipeGestureRecognizers for Chat?

And if so, since it seems the "swipe to left to bring out the chat list controller" is valid on every view controller, does it mean the same UISwipeGestureRecognizer is coded into every Controller? Or is there an easier way to do this without having to deal with this code repetition?

UPDATE

Think I got it working with rounak's answer, but to confirm - is this the right way to be doing it: since I have 3 Nav Controllers, with each one pointing to a View Controller, I should

(1) add the gestureRecognizer to my viewdidLoad in each of my View Controller's immediately connected to my Nav Controlllers

  UISwipeGestureRecognizer *swipeGesture = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipeGesture:)];
  swipeGesture.direction = UISwipeGestureRecognizerDirectionUp|UISwipeGestureRecognizerDirectionLeft;
  [self.navigationController.view addGestureRecognizer:swipeGesture];

(2) setup the action

-(void)handleSwipeGesture:(UISwipeGestureRecognizer *)sender {
  [self performSegueWithIdentifier:@"newSegue" sender:nil];
}

(3) Tie a segue from each of my View Controller's to the View Controller I want to show via Storyboard (ctrl + click), and name it appropriately

SimplyLearning
  • 269
  • 3
  • 11

1 Answers1

0

I'm guessing, yes they might be using gesture recognizers.

If you have multiple viewcontrollers inside a UINavigationController, you can simply add the gesture recognizer to navigationController.view

rounak
  • 9,217
  • 3
  • 42
  • 59
  • Do Navigation Controller's have a view? I only see the Navigation Bar, First Responder, Exit, and Relationship "root view controller"... My setup is Tab Bar Controller -> 3 Nav Controllers, each with more view controllers – SimplyLearning Apr 05 '14 at 10:09
  • Yes nav controllers are a view controller subclass, so they have a .view property – rounak Apr 05 '14 at 14:26
  • Awesome, thanks - marked as answered. Updated my initial post, you mind just confirming if that's the appropriate way to be doing this since I have three view controllers? – SimplyLearning Apr 05 '14 at 14:56
  • I haven't worked with Storyboards/IB, so not sure what performSegue does, but the gesture handling looks correct. – rounak Apr 05 '14 at 15:07
  • One other question if you might be able to help, realized there is a huge difference in how the FB app detects gestures, as any gesture from right to left will begin to open up the controller (ie. incrementally the controller will slide out to the left). Whereas using UISwipeGestureRecognizer will only detect a full swipe (oftentimes inaccurately). Would you happen to know how to detect any and all gestures from the right to left direction and how I could use that to slowly bring out my controller? – SimplyLearning Apr 08 '14 at 11:24
  • Use `UIPanGestureRecognizer` – rounak Apr 08 '14 at 13:29