找到单指点击目标

时间:2013-03-30 13:43:12

标签: ios objective-c

我有一组类似的对象(缩略图),我在其上添加了一个singleFingerTap识别器:

UITapGestureRecognizer *singleFingerTap =
    [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(backgroundThumbnailTapped)];
    [self addGestureRecognizer:singleFingerTap];

我怎样才能在我的选择器(backgroundThumbnailTapped)中知道哪些缩略图被点击?

1 个答案:

答案 0 :(得分:3)

更改选择器的签名以接受手势识别器,如下所示:

-(void) backgroundThumbnailTapped:(UIGestureRecognizer *)gestureRecognizer {
    // Below, you can get the view to which the recognizer is attached:
    [gestureRecognizer.view doSomething];
    //                 ^^^
    //                  |
    //     This is the view in which the tap was triggered
}

添加识别器时需要添加冒号:

UITapGestureRecognizer *singleFingerTap =
    [[UITapGestureRecognizer alloc] initWithTarget:self
        action:@selector(backgroundThumbnailTapped:)];
//                                 Here ----------^
    [self addGestureRecognizer:singleFingerTap];