views:

207

answers:

2

Hi,

I'm trying to find a good way to make a tap show/hide my menus, in the same way as iBooks. I set up UITapGestureRecognizer to do this, but unfortunately it means then that none of the buttons on the screen work. I know I can use

tapRecognizer.cancelsTouchesInView = NO;

in order to allow the touches to go through, but then of course, both things happen and I can't cancel the menu show/hide.

Is there a way for me to stop the UITapGestureRecognizer from happening on certain buttons or actions? Or is there a better way of doing this in general?

Thanks very much in advance for any help you can give me!

:-Joe

+1  A: 

I've solved it (or someone else solved it for me) so I thought I'd share with you:

Return NO from the delegate method gestureRecognizer:shouldReceiveTouch: if touch.view is one of your buttons.

Joe
Awesome, thanks for sharing your solution! I had the exact same problem.
The WebMacheter
+1  A: 

In case someone needs a little code to understand Joe's solution, you should first implement the UIGestureRecognizerDelegate protocol (i.e @interface YourViewController : UIViewController <UIGestureRecognizerDelegate>).

In the class that implements the UIGestureRecognizerDelegate protocol, you have to implement - (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch. There, you can check if touch.view is a button. In my implementation, I only used a return !([touch.view isKindOfClass:[UIButton class]]); but you may need to extend this if you have other touch-enabled components in which you don't want to trigger your tap recognizer.

The WebMacheter