在需要给图片,图标等控件添加 点击效果,手势效果的UITapGestureRecognizer用法
直接看代码示例:
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
UIImageView *imgView =[[UIImageView alloc] initWithFrame:CGRectMake(0, 0,320,100)];
imgView.backgroundColor = [UIColor redColor];
//因为没有设置image属性,为了显示出图片覆盖区域
imgView.userInteractionEnabled=YES;
UITapGestureRecognizer *singleTap =[[UITapGestureRecognizer alloc]initWithTarget:self
action:@selector(onClickImage)];
[imgView addGestureRecognizer:singleTap];
[self.view addSubview:imgView];
}
//处理单指事件
- (void)handleSingleFingerEvent:(UITapGestureRecognizer *)sender{
if(sender.numberOfTapsRequired == 1) {
//单指单击
NSLog(@"单指单