UIButton touches inside an event not working in ios5, while this is normal in ios6

I had a project that contains many UIButton using xcode 4.5 and storyboard and ARC. after testing in ios6 everything is going well. But in ios5, UIButton does not fire inside an event, and the action is not called. I tried using touch down and it works. However, I have a lot of UIButton, I cannot change this one at a time. what more, a touch event really gives a good experience.

I used the code below in many controllers of my view: in viewDidLoad:

UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(dismissKeyboard)]; [self.view addGestureRecognizer:tap]; -(void)dismissKeyboard { [aTextField resignFirstResponder]; } 

This may be the reason. I will check it later. But it works in ios6. Do you know what happened? Many thanks!

+7
source share
3 answers

I had the same problem. This is because the touch event in iOS5 is prevented when a recorded gestureRecognizer event captures the event.

There are two solutions.

One:

1) Add a new look inside your view. It should have the same level for the buttons. The priority of the buttons should be higher than the new one.

2) change the call to "addGestureRecognizer" to a new view.

 [self.newView addGestureRecognizer:tap]; 

Two:

1) Enter the code below. You must return NO when the dot is in the buttons.

 - (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer { CGPoint point = [gestureRecognizer locationInView:self.view]; NSLog(@"x = %.0f, y = %.0f", point.x, point.y); if (CGRectContainsPoint(self.testBtn.layer.frame, point)) return NO; return YES; } 

ps. You must import QuartzCore.h to access the level attributes.

 #import <QuartzCore/QuartzCore.h> 
+16
source

Just use the "cancelsTouchesInView" (NO) property on the UITapGestureRecognizer tab

Example:

 UITapGestureRecognizer *gesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(didTap)]; gesture.cancelsTouchesInView = NO; [self.view addGestureRecognizer:gesture]; 
+5
source

Override the parent pointinside method of your element by setting the new size of the custom frame containing your button.

0
source

All Articles