label.userInteractionEnabled = YES;//设置userInteractionEnabled属性为yes。
UITapGestureRecognizer *labelTap = [[UITapGestureRecognizer alloc] initWithTarget:selfaction:@selector(labelTap:)];//初始化一个单击手势
[label
如果是添加长按事件,则是UILongPressGestureRecognizer。
方法二:添加一个他们的子类,重写view的touch方法
#import
@interface untitled : UIImageView {
}
@end
#import "untitled.h"
@implementation untitled
- (id)initWithFrame:(CGRect)frame {
}
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
}
-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
}
-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
}
- (void)dealloc {
}
@end
在touch事件种添加你自己想要的操作就可以了
然后定义自己的image就用untitled就可以了