Limits in multiple touches in iPhone OS

Most people are familiar with the multiple touch interface in the iPhone OS. Using two fingers for pinching and rotating are common in many applications. Some applications even allow you to use three fingers. In developing my latest app called multiTouch the Game, I found a limitation in the iPhone SDK that is not documented anywhere.

If you are not familiar with how to use touch routines, the 'iPhone OS Programming Guide' is a very good reference. Throughout the documentation, there are references to 'one or more fingers'. Through experimentation, I found that the 'one or more' to be actually 'up to five'.

The rest of this document will describe what happens when you have more than five touches occurring at the same time.

There are four main events that are used when a finger is touching the screen.

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event;
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event;
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event;
- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event

Each one of these events contains a NSSet of UITouch objects. A single UITouch objects represents one finger. When an event is called, one or more UITouch objects may be sent. Depending on when a particular finger is in motion, the NSSet can contain up to five objects. As long as there is a change in finger status at least one of these events are called. If the user moves a finger before setting another down, then you will receive a Began, Moved, Began sequence. To determine when all the fingers have been lifted, you have to track how many are currently down, since the touchesEnded event is called when one or more fingers are lifted, which may or may not be all the fingers.

When you place the sixth finger down, the touchesCancelled event is called. Once this occurs, then information about the other finger positions are lost. You cannot get any more Moved or Ended events for those fingers, even though they may still be touching the screen. The limit of five makes sense, since most people only have five fingers on one hand. According to the Apple documentation "the touch sequence is cancelled by a system event, such as an incoming phone call." Perhaps six fingers down triggers an exception. Regardless, you should handle the touchesCancelled event and reset whatever is necessary. It is interesting that even after the touchesCancelled is called, if you remove some of your fingers, but leave the others on, only the new touches will create an Event. The old fingers won't register, but they are still counted, since if you put more than five fingers back on, another Cancelled event is triggered.

You can try out my 'multiTouch the Game' application on the App Store. It's free, and fun. I had hoped to use up to eight fingers, but had to limit it to five because of the OS restriction. Maybe in a future OS version the limit will increase.

MacBook, 2 GHz Intel Core 2 Duo

Posted on Aug 17, 2009 3:00 PM

Reply

There are no replies.

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Limits in multiple touches in iPhone OS

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.