Search code examples
iphoneobjective-cuitouch

Detecting hold on a object - iPhone Objective C


How can I detect if a user holds their finger down on an onscreen object for 1 second ?

Thanks,

Martin


Solution

  • You need at least one state variable and a timer.

    On a touch down inside inside the target area, set the state variable with the current time and start a 1 second timer. On any touch move outside the target area or touch up event, clear the state variable. After the 1 second timer has gone off, check the state variable. If it still has a time from 1 second ago or more (and thus hasn't been cleared or changed), then the touch has been on target for at least 1 second.