我是手势识别器的新手,所以这个问题可能听起来很傻:我正在将点击手势识别器分配给一组UIView.在这个方法中,是否有可能找出它们中的哪一个是以某种方式被点击的,或者我需要使用屏幕上被点击的点来找出它?

for (NSUInteger i=0; i<42; i++) {
        float xMultiplier=(i)%6;
        float yMultiplier= (i)/6;
        float xPos=xMultiplier*imageWidth;
        float yPos=1+UA_TOP_WHITE+UA_TOP_BAR_HEIGHT+yMultiplier*imageHeight;
        UIView *greyRect=[[UIView alloc]initWithFrame:CGRectMake(xPos, yPos, imageWidth, imageHeight)];
        [greyRect setBackgroundColor:UA_NAV_CTRL_COLOR];

        greyRect.layer.borderColor=[UA_NAV_BAR_COLOR CGColor];
        greyRect.layer.borderWidth=1.0f;
        greyRect.userInteractionEnabled=YES;
        [greyGridArray addObject:greyRect];
        [self.view addSubview:greyRect];
        NSLog(@"greyGrid: %i: %@", i, greyRect);

        //make them touchable
        UITapGestureRecognizer *letterTapRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(highlightLetter)];
        letterTapRecognizer.numberOfTapsRequired = 1;
        [greyRect addGestureRecognizer:letterTapRecognizer];
    }

推荐答案

将目标 Select 器(highlightLetter:)定义为

UITapGestureRecognizer *letterTapRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(highlightLetter:)];

然后你就可以通过

- (void)highlightLetter:(UITapGestureRecognizer*)sender {
     UIView *view = sender.view; 
     NSLog(@"%d", view.tag);//By tag, you can find out where you had tapped. 
}

Objective-c相关问答推荐

使用自动布局自定义纵横比

UIButton 标题更改为默认值

如何将变量参数传递给另一个方法?

为 iphone 应用程序设置自动构建服务器的最佳实践?

在 Objective-C 中在 iPhone 上使用 HTTP POST 和 GET 的教程

在 macOS 10.9+ 上删除 plist 文件不会重置应用程序

在Objective-C中从类名的NSString创建对象

iOS - UITableViewCell 中 UIButton 的延迟Touch Down事件

在运行时判断 iOS 版本?

在 Xcode 5 中运行代码覆盖时出现数十个profiling:invalid arc tag

滚动后检测 UITableView 中的当前顶部单元格

当服务器上的图像文件更改时,我的应用程序中的 SDWebImage 缓存图像会发生什么情况?

检测 iOS 应用程序是否在调试器中运行

UITextField:键盘出现 timeshift 动视图

导航返回时重新加载 UITableView?

UIView: opaque vs. alpha vs. opacity

如何在今天午夜获取 NSDate 对象?

将自定义子视图(在 xib 中创建)添加到视图控制器的视图 - 我在做什么错

未调用 cellForItemAtIndexPath 但 numberOfItemsInSection 调用

UICollectionView:如何检测滚动何时停止