我有一组类似的对象(缩略图),我在其上添加了一个singleFingerTap识别器:
UITapGestureRecognizer *singleFingerTap =
[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(backgroundThumbnailTapped)];
[self addGestureRecognizer:singleFingerTap];
我怎样才能在我的选择器(backgroundThumbnailTapped)中知道哪些缩略图被点击?
答案 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];