我使用了一个 Collection View 单元格来显示多个图像。然后每张图片的右上角都会有一个小图标。我的问题是如何将点击手势添加到每个单元格图像右上角的小图标。
我的代码:
UITapGestureRecognizer *tapped = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(projectSetting:)];
_projectSettingIconButton = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"login-settings.png"]];
_projectSettingIconButton.frame = CGRectMake(95, 3, 21, 21);
[_projectSettingIconButton addGestureRecognizer:tapped];
[cell addSubview:_projectSettingIconButton];
最佳答案
试试这个
在图标上添加点击手势识别器:
UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleSingleTap:)];
[YOURICON addGestureRecognizer:singleTap];
然后添加
-(void)handleSingleTap:(id)sender
{
// do your stuff;
}
关于Ios- Ipad- UicollectionViewCell- 单元格上的图标- 如何在 xcode 5 中向图标添加点击手势?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22171848/