I want to turn off touches in all areas of the screen, except for certain several points (for example, buttons). That is, I don’t want touchhesBegan to start at all when I clicked anything but a button. Call
self.view.userInteractionEnabled = NO;
has the desired effect in order not to register touches, but then, of course, I can’t press any buttons. I basically want the button to still work , even if 5 dots hit the screen, i.e. All touch inputs were used, and the button represents the 6th.
Is it possible?
I tried to insert a view with userInteraction disabled below my buttons, but it still registers touches when the user picks up the screen. It seems that the only way to turn off the registration of touches is to do it on the whole screen (on the parent UIView).
UPDATE: I tried using gesture recognizers to handle all touch events and ignore those that don't meet the requirements. Here is my code:
@interface ViewController : UIViewController <UIGestureRecognizerDelegate>
...
- (void)viewDidLoad { [super viewDidLoad]; UIGestureRecognizer *allRecognizer = [[UIGestureRecognizer alloc] initWithTarget:self action:nil]; allRecognizer.delegate = self; [self.view addGestureRecognizer:allRecognizer]; } - (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch { CGPoint coords = [touch locationInView:self.view]; NSLog(@"Coords: %g, %g", coords.x, coords.y); if (coords.y < 200) { [self ignoreTouch:touch forEvent:nil]; return TRUE; } return FALSE; } - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { NSLog(@"%i touch(es)", [touches count]); }
However, the screen still “reads” the strokes, so if I put 5 fingers down, the 6th will not press the button ...
source share