All I want to know is how to I recognise when a user taps outside of the modal dialog. I have tried this but it is not being called when the user taps outside.
Here is my viewDidLoad method which resides in the ModalDialogViewController.m file UITapGestureRecognizer *recognizer;
if(![self.view.window.gestureRecognizers containsObject:recognizer])
{
recognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTapBehind:)];
//[recognizer setDelegate:self];
[recognizer setNumberOfTapsRequired:1];
recognizer.cancelsTouchesInView = NO; //So the user can still interact with controls in the modal view
[self.view.window addGestureRecognizer:recognizer];
}
This is not opening the handleTapBehind method.
I have made the modal view controller a protocol of UIGestureRecognition.
A bit late here, but just incase someone comes here by way of Google:
Setting up the gesture recognizer should happen after the view appears. During the viewDidLoad method invocation, the view's window is nil, so the gesture recognizer never gets added.
Put the method call in viewDidAppear and it should work as expected.