【问题标题】:Tap gesture added to UIImageView not responding添加到 UIImageView 的点击手势没有响应
【发布时间】:2016-10-02 07:49:37
【问题描述】:

我想让UIImageView 响应用户的点击。我在情节提要中添加图像视图,并为它们设置标签。然后在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 将手势识别器添加到图像视图,仍然没有响应。

有什么问题?

【问题讨论】:

  • 图像视图是以编程方式创建的?
  • 不,它们是使用情节提要添加的。
  • 不如创建 IBOutlets 并尝试
  • 试过了,但问题依然存在。 :-(
  • 尝试使用 UITapGestureRecognizer

标签: ios objective-c uiimageview uigesturerecognizer


【解决方案1】:

这是 LokeshChowdary 发现的一个错误。

在我的代码中,UIGestureRecognizer 应该是 UITapGestureRecognizer

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-04-20
    • 2012-05-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多