4

I'm adding a UIGestureRecognizer to one of my view controllers view.

My desired behaviour is when this gesture is recognised to dismiss the gestures view controller and forward it to another view controller. (the view controller I want to forward it has presented the view controller with the gesture)

Right now when I dismiss the view controller, the pinch gesture recogniser is (logically) failing.

Any suggestions? Thanks.

Devfly
  • 2,495
  • 5
  • 38
  • 56

3 Answers3

1

\EDIT: Now the delegate get the argument with the gestureRecognizer.

You can just implement protocol like:

@protocol ViewControllerWithGestureRecognizerDelegate

- (void)viewControllerGestureRecognizerEvent:(UIPinchGestureRecognizer *)gestureRecognizer;

@end

and add the delegate property to the view controller in which there will be presented gesture recognizer.

@property (nonatomic, weak) id<ViewControllerWithGestureRecognizerDelegate> delegate;

Then add the gesture recognizer to your view Controller:

 UIPinchGestureRecognizer *gestureRecognizer = [[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(gestureRecognizerAction:)];
[self addGestureRecognizer:gestureRecognizer];

Call the delegate method in action method of the gesture recognizer:

 - (void)gestureRecognizerAction:(UIPichGestureRecognizer *)gestureRecognizer
 {
   [self.delegate viewControllerGestureRecognizerEvent:gestureRecognizer];
 }

Implement the protocol ViewControllerWithGestureRecognizerDelegate in the second view controller (in which you want to get notified about gesture recognizer events) and set the delegate of the view controller which gesture recognizer to be the second view controller.

 ViewControllerWithGestureRecognizer.delegate = ViewControllerInWhichYouWantToGetNotifiedAboutGestureRecognizerEvents.

This way every time the gesture recognizer will call method on the the one view controller, the second one will be informed about that.

Rafał Augustyniak
  • 2,011
  • 19
  • 14
  • Thanks, but my gesture is continuous (UIPinchGestureRecognizer) so I want to forward the whole gesture instead of simply calling a method. – Devfly Jul 19 '13 at 08:40
  • I edited my answer so that second controller can have access to your gestureRecognizer. – Rafał Augustyniak Jul 19 '13 at 08:58
  • why not simply set the gestureRecognizer's delegate property to the other view controller, and make the otherVC conform to UIGestureRecognizerDelegate protocol? e.g gestureRecognizer.delegate = otherVC; – Kaan Dedeoglu Jul 19 '13 at 09:00
  • Thanks, but the problem here is when this pinch gesture is recognised I dismiss the view controller, so the pinch fails. – Devfly Jul 19 '13 at 13:09
0

You need to include delaysTouchesEnded until the gesture is recognized:

@property (nonatomic) BOOL delaysTouchesEnded
Jack
  • 131,802
  • 30
  • 241
  • 343
0

Will implementing this delegate method not solve your problem?

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer
shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer*)otherGestureRecognizer {
    return YES;
}
osxdirk
  • 560
  • 6
  • 11