嗨所以我想知道是否有可能通过UITapGestureRecognizer识别触摸位置以识别背景上的水龙头。
-(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];
}
}
}
答案 0 :(得分:1)
当然有!使用locationInView:
在图像视图中获取触摸的CGPoint位置。
CGPoint touchLocation = [sender locationInView:sender.view];
或者,如果您允许多次触摸,则可以使用以下内容指定您感兴趣的触摸。
CGPoint otherTouchLocation = [sender locationOfTouch:0 inView:sender.view];