1

嗨所以我想知道是否有任何方法可以获得使用 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];
    }
}
}
4

1 回答 1

2

当然有!用于locationInView:获取图像视图上触摸的 CGPoint 位置。

CGPoint touchLocation = [sender locationInView:sender.view];

或者,如果您允许多次触摸,则可以使用以下内容指定您感兴趣的触摸。

CGPoint otherTouchLocation = [sender locationOfTouch:0 inView:sender.view];
于 2013-08-08T22:43:35.360 回答