0

I want to track user touches on screen. the user can touch with two fingers and then remove 1 Or touch with one finger and immediately with another (there will be two fingers currently on the screen) then remove one finger. How to exactly track the touch 1 and touch 2

  • Since the user can swipe on the screen which calls touchesmoved, the touches are changing randomly. Is there a way I can the touches in the right order. – Nagavardhan Venkata Apr 15 '17 at 22:17

1 Answers1

1

I don't quite understand what you mean by saying "remove 1 Or touch with one finger and immediately with another." I assume what you're looking for is to track multiple touches. If so, see my answer here.

The basic concept for this is to store each UITouch ID in an array when touchesBegan:: called, and later compare each ID with the touches on screen on touchesMoved:: event. This way, each finger can be paired with a single object, and be tracked along when panning.

If you only want to track two fingers, simply set MAX_TOUCHES to 2. Hope this helped.

Community
  • 1
  • 1
J1soon
  • 357
  • 1
  • 7
  • 13
  • Both fingers are moved and the user takes one finger off the screen. How would I know if it is touch 1 or 2? – Nagavardhan Venkata Apr 16 '17 at 14:21
  • Use `NSArray *allTouches = [touches allObjects];` to get the touches with a certain event, and then `UITouch *touch = allTouches[i];` to get the touch you want to track. You would probably want to save it in a variable for later comparison to identify which touch it is. – J1soon Apr 16 '17 at 16:46
  • my requirement is for 2 fingers. User can swipe with both Fingers or (one finger is moving and other is stationary) or When swiping, the user would remove one finger (Here i want to exactly know which finger got removed) – Nagavardhan Venkata Apr 17 '17 at 03:45
  • So what kind of result do you want to achieve? Panning, swiping, pinching, or tapping? Make sure you know the difference between these gestures. – J1soon Apr 19 '17 at 01:28
  • I am developing a keyboard for iOS. – Nagavardhan Venkata Apr 19 '17 at 11:59
  • 1. If user touches at one point and ends at the same point, consider it as a tap 2. If the user touches at one point and moves to the next letter (in keyboard from A to s) then consider it as swipe. Both the actions can happen simultaneously (while swiping on the left side of the keyboard, the user can tap a letter on the right. I want to exactly track which finger is moved/tapped/removed – Nagavardhan Venkata Apr 19 '17 at 12:07
  • OK, I think I understand. So you want to handle two different kind of gestures, a pan and a tap, correct? (Swipe usually refers to four directions: up, down, left, right, as shown [here](https://developer.apple.com/reference/uikit/uiswipegesturerecognizerdirection). For "any" direction, I would call it a "pan".) – J1soon Apr 19 '17 at 12:38
  • Now this would be much easier to handle than tracking multi-touches. All you have to do is to create a `UIPanGestureRecognizer` and a `UITapGestureRecognizer`, and then use this delegate shown [here](https://developer.apple.com/reference/uikit/uigesturerecognizerdelegate/1624208-gesturerecognizer?language=objc) to make them work simultaniously. How to track exactly "which finger?" Just handle the two gesture recognizers separately, as answered [here](http://stackoverflow.com/a/11355713/6109712). – J1soon Apr 19 '17 at 12:39
  • I kind of modified your code http://stackoverflow.com/a/43435058/6109712 . Is there a to know that there are no touches on the screen? i believe that would solve the problem – Nagavardhan Venkata Apr 19 '17 at 21:21
  • You can try creating an integer that counts the number of touches on screen. Add the number of `[[touches allObjects] count]` to the counter on `touchesBegan`, and subtract the number of `[[touches allObjects] count]` on `touchesEnded` and `touchesCancelled`. Tell me how it goes:) – J1soon Apr 19 '17 at 23:06