IPhone - ignoring second touch area

I have an opinion that users are allowed to draw with their finger. The code works fine if the area is touched with one finger. For example: I touch it with one finger and move my finger. Then the line is drawn when I move the first finger. If I touch with the second finger of the same kind, the line that was drawn with the first finger stops.

I would like to ignore any touch after the first, i.e. track the first touch, but ignore everyone else in the same view.

I am using touchhesBegan / moved / completed.

I used this to detect touch

UITouch *touch = [[event allTouches] anyObject];
lastPoint = [touch locationInView:myView];

I also tried this

lastPoint = [[touches anyObject] locationInView:myView];

but nothing has changed.

How do I do this - track the first touch and ignore any subsequent touch on the view?

thank.

: .

+3
2

, . , . . , , .

:

currentTouch :

@interface MyView : UIView {
    UITouch *currentTouch;
    ...
}
...
@end

touchesBegan:, , :

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
    if(currentTouch) return;
    currentTouch = [touches anyObject];
    ...
}

touchesMoved:, currentTouch , :

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
    if(!currentTouch) return;
    CGPoint currentPoint = [currentTouch locationInView:myView];
    ...
}

touchesEnded: touchesCancelled:, currentTouch, currentTouch .

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
    if(currentTouch && currentTouch.phase == UITouchPhaseEnded) {
        ...
        currentTouch = nil;
    }
}
- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event {
    if(currentTouch && currentTouch.phase == UITouchPhaseCancelled) {
        ...
        currentTouch = nil;
    }
}
+3
yourView.multipleTouchEnabled = NO;

UIView

multipleTouchEnabled

, , .

@property (, getter = isMultipleTouchEnabled) BOOL

YES, , . , . .

, . - , Touch YES.

0

All Articles