how do i disable touchesBegan: for multi-touches?
Asked Answered
C

5

7
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event

I am currently getting 1 object in

touches 

when I do a tap with two fingers simultaneously (holding option key and clicking on the simulator). I believe this is because I haven't enabled the

multipleTouchEnabled 

property of the attached view. I want to make it so that I don't register this event for multi-touches.

Looking into the issue, it seems like it would work if I enable multipleTouchEnabled, and then do

if ([touches count] > 1) {
    return;
}

in my

touchesBegan:

However, this seems strange to me in that I am ENABLING multipleTouchEnabled to DISABLE multiple touches, and am worried if there will be side-effects. Is there a better way to solve my problem?

Chinaman answered 11/2, 2013 at 21:52 Comment(1)
Keep in mind: on a real device, it's unlikely that the user's fingers will touch the screen at exactly the same time. You should be prepared for -touchesBegan: to be called twice (or more) with different touches.Percaline
K
2

You should just be able to disable the multitouch property on the view , in IB you have to actually go over to the side panel and click on the thing that says view next to files owner to get it and then uncheck it, or you could do it in code in viewdidload:

self.view.multiTouchEnabled = NO;

Kellby answered 19/2, 2013 at 9:25 Comment(0)
C
1

First add a gesture recognizer to your view:

UITapGestureRecognizer *multipleTouches = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleMultiTap:)];
multipleTouches.numberOfTouchesRequired = 2;
[yourViewName addGestureRecognizer:multipleTouches];
[multipleTouches release];

Hope it will help you.

Coddle answered 18/2, 2013 at 6:13 Comment(0)
H
0

You could use a gesture recognizer, this is probably more readbale than the touches delegate even if your code works:

UITapGestureRecognizer *gestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(myAction:)];
gestureRecognizer.numberOfTouchesRequired = 2;
Honeyed answered 11/2, 2013 at 22:29 Comment(0)
C
0

If it is compulsory to use NSTouches then you can use the following methods to get the desired task achieve.

[view setMultipleTouchEnabled:NO];
[view setExclusiveTouch:YES];

more over you can play with

setMultipleTouchEnabled:

by keeping

view's setExclusiveTouch to YES

Coactive answered 15/2, 2013 at 0:8 Comment(0)
I
0

You can use this line to avoid multiple touches at a point, set exclusive touch "Yes" to your view.

[self.view setExclusiveTouch:YES];
Irtysh answered 24/8, 2016 at 9:22 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.