sol
sol

Reputation: 6462

iOS - detect when more than one finger is on the screen

I'm looking for the best way to detect more than one finger on the screen at time. I'm not detecting taps or pinching, just the fact that more than one touch is happening. There don't seem to be any gesture recognizers for that. What's the best way?

Upvotes: 9

Views: 9853

Answers (5)

amisha.beladiya
amisha.beladiya

Reputation: 363

  • (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {

    NSLog(@"%lu",[[event allTouches] count]); }

Upvotes: 1

William Jockusch
William Jockusch

Reputation: 27295

In the touchesBegan, touchesMoved, and touchesEnded methods, one parameter is event, which is a UIEvent object. The number of fingers on the screen is [[event allTouches]count].

[EDITED because Josh Hinman pointed out that I had it wrong before -- my previous suggestion of using [touches count] on the touches parameter in those same methods will not work.]

Upvotes: 14

Kris Markel
Kris Markel

Reputation: 12112

You can try using a UITapGestureRecognizer class, and set the numberOfTouchesRequired property to 2.

Note that this will only work if multipleTouchEnabled is set to YES on the view.

Upvotes: 0

Dan Ray
Dan Ray

Reputation: 21893

Read up on the -touchesBegan:withEvent: method. It's the entry point into multi-touch event handling.

Here's a developer's lib link on multitouch events: https://developer.apple.com/library/ios/#documentation/EventHandling/Conceptual/EventHandlingiPhoneOS/MultitouchEvents/MultitouchEvents.html

Upvotes: 4

Danra
Danra

Reputation: 9906

One/Multi touch is transparent to you - You just get notifications on where a touch started/moved/ended/tapped. If two touches occur at the same time, you will get notifications for both.

I don't know of any built-in function which determines whether or not the touch sequences you see consist of a pinch - But you can take a look at the "touches" sample code from Apple for inspiration.

https://developer.apple.com/library/ios/#samplecode/Touches/

Upvotes: 0

Related Questions