Im trying to find out how to detect a touch&hold on screen method in the game im making. Im using touches began for single taps (Making the character move up) When they touch and keep holding i want the character to move straight forward.

```
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {

 //code to make him move up

    }

```

Any ideas on how to detect a touch&hold ?
['https://Stackoverflow.com/questions/44629249', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/6151911/']
**Objective-c** 

```
// Add guesture recognizer
UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(buttonDidLongPress:)];
    [self.button addGestureRecognizer:longPress];

// Call back event
- (void)buttonDidLongPress:(UILongPressGestureRecognizer*)gesture
{
    switch (gesture.state) {
        case UIGestureRecognizerStateBegan:
        {
            // Code
        }
            break;
        case UIGestureRecognizerStateEnded:
        {
            //Code
        }
            break;
        default:
            break;
    }
}

```

**Swift**

```
// Add guesture recognizer
        let longPress = UILongPressGestureRecognizer(target: self, action: #selector(longPress(_:)))
        self.button.addGestureRecognizer(longPress)

// Call back event
func longPress(guesture: UILongPressGestureRecognizer) {

        switch guesture.state {
        case UIGestureRecognizerState.began:
            //Code
            break

        case UIGestureRecognizerState.ended:
            //Code
            break

        default:
            break
        }
    }

```

Don't forgot to extend you class with UIGestureRecognizerDelegate
Try:

```
UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(handleLongPress:)];
[self.view addGestureRecognizer:longPress];

-(void) handleLongPress: (UIGestureRecognizer *)longPress {
switch (longPress.state) {
    case UIGestureRecognizerStateBegan:
        // Called when long press for minimum time duration
        break;
    case UIGestureRecognizerStateChanged:
        // Long pressed and dragged 
        break;
    case UIGestureRecognizerStateRecognized:
        // Successfully recognised Long touch
        break;

    default:
        break;
}
if (longPress.state==UIGestureRecognizerStateEnded) {
    NSLog(@"LONG PRESSED");
}

```

}