views:

114

answers:

3

I'm trying to introduce a delay between a "touch began" event and an action such as playing a sound. After the threshold has passed, if the user's finger stays relatively stationary, then I hope to increase the volume gradually until the finger is lifted or dragged out of the rectangular area of effect. If it drags out I might play a different sound.

I'm starting off with the delay but I don't know how to determine the length of time a finger is held in a position.

+1  A: 

The messages you get for touch are when you lift the finger or move the finger. Assuming your app only supports single touch, this should be pretty easy. If you support multitouch, you'll need to figure out which finger is which as they move.

Nosredna
+1  A: 

You will need to set up a timer you fire to increase your volume every 1/10s say.

You could either count these timer events or you culd store an [NSDate date] in your touchesBegan and then inspect that as your other events occur - touches moved that stays inside your rect or the timer.

The latter is a more flexible approach and not a significant overhead.

Roger Nolan
A: 

This blog post might be helpful,

How Long was a Touch Event – Detecting When a Touch Event Starts and Ends

John