views:

54

answers:

2

The best method I can think of is to start a timer in the touchesBegan event method. If the timer expires before the touchesEnded event arrives, then you know the user is holding down on the screen. If the touchesMoved event is called, then simply reset the timer so as to only detect holding down without movement.

Is there any functionality built into the iOS SDK to handle exactly this? Or any better, simpler, faster methods anyone can think of?

Thanks in advance for your help!

+1  A: 

I don't know of another way to test for no movement; I think how you are doing it would be simple enough.

You will most likely not be able to use touchesMoved to reset the timer since it is very, very sensitive and you move your finger without even being able to see it with the naked eye (feel free to test this with NSLogs to see what I mean).

You may want to implement some type of threshold difference value for how much the touchesMoved value has changed from the original value before you reset the timer.

iWasRobbed
very good idea, thanks!
BeachRunnerJoe
+1  A: 

Try using the UILongPressGestureRecognizer.

UILongPressGestureRecognizer* gr = [[UILongPressGestureRecognizer alloc]
                                    initWithTarget:theTarget
                                            action:@selector(someAction:)];
// change options of gr if you like.
// default: tolerate movement up to 4 px, fire the event after 0.4 secs.
[theView addGestureRecognizer:gr];
[gr release];

When the user long-pressed [theTarget someAction:gr] will be called.

KennyTM