Try this:
BOOL _justPressed; // Declare this in your @interface
...
- (void)unsetJustPressed {
_justPressed = NO;
}
Then, in your touchesMoved
:
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
if (_justPressed) {
// A key was just pressed, so do nothing.
return;
}
else {
_justPressed = YES;
// Do stuff here
[self performSelector:@selector(unsetJustPressed)
withObject:nil
afterDelay:0.25];
}
}
This way, you set a variable _justPressed
to YES
every touchesMoved:withEvent:
is called (or within a specific conditional in there, depending on what you want to do), and you use performSelector:withObject:afterDelay:
to set _justPressed
to NO
after a certain time period, and so you can just check whether _justPressed
is YES
when touchesMoved:
is called to ascertain whether it was called recently.
Remember, you don't have to return from the method like in the example above, you can simply use _justPressed
to check whether you should play the sound, but still perform your other actions. The example is just to give you a basic idea of what to do.