Cocoa Dev
Cocoa Dev

Reputation: 9541

iOS how to determine if the screen has been tapped

I am using iOS 5.x SDK and I want to determine if the screen has been tapped

For now just putting up an NSLog is fine but I don't know where to start

Upvotes: 0

Views: 1012

Answers (2)

Sierra Alpha
Sierra Alpha

Reputation: 3727

You might want to start with implementing touchesBegan:withEvent:, touchesMoved:withEvent:, touchesEnded:withEvent:, touchesCancelled:withEvent:.

You can read more about it here: UIResponder Class Reference

Upvotes: 1

Rob
Rob

Reputation: 437452

Generally with gesture recognizers, e.g.,

UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapOnView:)];
[self.view addGestureRecognizer:tap];

You then have a method like:

- (void)tapOnView:(UITapGestureRecognizer *)sender
{
    CGPoint location = [sender locationInView:self.view];
    NSLog(@"Tap at %1.0f, %1.0f", location.x, location.y);
}

Upvotes: 3

Related Questions