gpt4 book ai didi

ios - 点击手势识别器 - 哪个对象被点击了?

转载 作者:IT老高 更新时间:2023-10-28 11:35:18 26 4
gpt4 key购买 nike

我是手势识别器的新手,所以这个问题可能听起来很傻:我正在将点击手势识别器分配给一堆 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];
}

最佳答案

用参数定义你的目标选择器(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.
}

关于ios - 点击手势识别器 - 哪个对象被点击了?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21573036/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com