Вам необходимо реализовать все три метода, например:
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
_touchMoved = NO;
}
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
_touchMoved = YES;
}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
if ( !_touchMoved ) {
// good we just tapped!
// here you can also check for time difference between when touches began and ended
}
}
Однако, если вы ищете "Долгое нажатие", рассмотрите возможность использования распознавателей жестов, в частности UILongPressGestureRecognizer
.Вы можете создать экземпляр UILongPressGestureRecognizer
и прикрепить его к своему виду, используя -(void)addGestureRecognizer:(UIGestureRecognizer *)gestureRecognizer
, определенный для любого UIView