在UIImage上添加点击手势 [英] Adding Tap Gesture on UIImage

查看:87
本文介绍了在UIImage上添加点击手势的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图制作可点击的UIImage,用户可以在其中单击它,然后对其进行动画处理。

I am trying to make clickable UIImage, where the user can click it then it'll animate...

我正在使用UIScrollVIew,这就是为什么我使用UITapGesture而不是touchesBegan,看来UIGestureRecognizer与UIImage不兼容...

i am working with the UIScrollVIew that's why i used the UITapGesture instead of touchesBegan, and it seems that UIGestureRecognizer is not compatible with UIImage...

我对吗?

我一直收到此错误消息


实例消息的接收者类型'UIImage'没有声明带有选择器的方法
'addGestureRecognizer'

receiver type 'UIImage' for instance message does not declare a method with selector 'addGestureRecognizer'

还有其他方法吗?

推荐答案

您必须在UIImageView中添加TapGesture而不是UIImage

You have to add TapGesture in UIImageView not UIImage

imgView.userInteractionEnabled = YES;

UITapGestureRecognizer *tapGesture1 = [[UITapGestureRecognizer alloc] initWithTarget:self  action:@selector(tapGesture:)];

tapGesture1.numberOfTapsRequired = 1;

[tapGesture1 setDelegate:self];

[imgView addGestureRecognizer:tapGesture1];

[tapGesture1 release];

您可以使用定义的选择器来响应水龙头,然后在其中进行填充

You can response to the tap with the defined selector and do stuff there

- (void) tapGesture: (id)sender
{
    //handle Tap...
 }

这篇关于在UIImage上添加点击手势的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆