将 UITapRecognizerController 添加到 UIImageView

Posted

技术标签:

【中文标题】将 UITapRecognizerController 添加到 UIImageView【英文标题】:Add UITapRecognizerController to UIImageView 【发布时间】:2013-06-12 13:30:01 【问题描述】:

我有一个imageview,我添加了一个tapRecognizer 来喜欢这个:

recognizer1 = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTap1)];

UIImageView *crossImage = [[UIImageView alloc] initWithFrame:CGRectMake((jrect.origin.x+jrect.size.width), (jrect.origin.y-20), 30, 30)];
crossImage.image = [UIImage imageNamed:@"cross.png"];
[crossImage addGestureRecognizer:recognizer1];
[self addSubview:crossImage];

handleTap方法:

- (void)handlePan1:(UITapGestureRecognizer *)recognizer

    NSLog(@"FV");

当我单击图像时,没有任何反应。怎么了?

【问题讨论】:

【参考方案1】:
crossImage.userInteractionEnabled = YES;

您需要启用用户迭代。 UIImageView 默认为 NO。

【讨论】:

以上是关于将 UITapRecognizerController 添加到 UIImageView的主要内容,如果未能解决你的问题,请参考以下文章