添加到UIImageView的点击手势无响应

时间:2016-10-02 07:49:38

标签: ios objective-c uiimageview uigesturerecognizer

我想让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向图像视图添加手势识别器,仍然没有响应。

问题是什么?

1 个答案:

答案 0 :(得分:0)

这是LokeshChowdary发现的一个错误。

在我的代码中,UIGestureRecognizer应为UITapGestureRecognizer