Reputation: 315
Hi so I was wondering if there was any way possible to get the position that was touched using UITapGestureRecognizer to recognize taps on the background.
-(void)handleTapGesture:(UITapGestureRecognizer *)sender {
if (sender.state == UIGestureRecognizerStateRecognized)
{
if ( bomb == nil)
{
bomb = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"bomb.png"]];
bomb.center = CGPointMake(10, 1);
bomb.frame = CGRectMake(113,123,67,67);
[self.view addSubview:bomb];
//[self performSelector:@selector(Update) withObject:nil afterDelay:1];
NSLog(@"Spawned bomb");
timer = [NSTimer scheduledTimerWithTimeInterval:.01 target:self selector:@selector(dropBomb) userInfo:nil repeats:YES];
}
}
}
Upvotes: 1
Views: 197
Reputation: 130222
Sure there is! Use locationInView:
to get the CGPoint location of the touch on your image view.
CGPoint touchLocation = [sender locationInView:sender.view];
Or, if you are allowing multiple touches, you can use the following to specify which touch you are interested in.
CGPoint otherTouchLocation = [sender locationOfTouch:0 inView:sender.view];
Upvotes: 2