我想让UIImageView
回复用户点按。我在storyboard中添加图像视图,并为它们设置标签。然后在viewDidLoad
:
UIGestureRecognizer *tapGesture = [[UIGestureRecognizer alloc] initWithTarget:self action:@selector(openCourseView:)];
[self.view viewWithTag:IMAGE_VIEW_TERM].userInteractionEnabled = YES;
[self.view viewWithTag:IMAGE_VIEW_1V1].userInteractionEnabled = YES;
[self.view viewWithTag:IMAGE_VIEW_SPECIAL].userInteractionEnabled = YES;
[[self.view viewWithTag:IMAGE_VIEW_TERM] addGestureRecognizer:tapGesture];
[[self.view viewWithTag:IMAGE_VIEW_1V1] addGestureRecognizer:tapGesture];
[[self.view viewWithTag:IMAGE_VIEW_SPECIAL] addGestureRecognizer:tapGesture];
但我的回复方法openCourseView:
从未调用过。然后我尝试使用IBOutlet
向图像视图添加手势识别器,仍然没有响应。
问题是什么?
答案 0 :(得分:0)
这是LokeshChowdary发现的一个错误。
在我的代码中,UIGestureRecognizer
应为UITapGestureRecognizer
。