1 #pragma mark - 添加Tab手势 2 -(void)createTabGR{ 3 4 //创建一个Tab点击手势 5 //发生点击后调用本类的tap方法,把tgr传入 6 UITapGestureRecognizer * tgr = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tap:)]; 7 //默认敲击次数为 1 8 //所有的UIview的子类视图都可以添加手势 9 //把手势添加到图片视图上 10 [_imageView addGestureRecognizer:tgr]; 11 12 //添加双击手势 13 UITapGestureRecognizer * doubletgr = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(doubleTap:)]; 14 //设置敲击次数为2 15 doubletgr.numberOfTapsRequired = 2; 16 17 [_imageView addGestureRecognizer:doubletgr]; 18 19 //设置满足双击的情况下不触发单机 20 [tgr requireGestureRecognizerToFail:doubletgr]; 21 22 } 23 24 //单次手势事件 25 -(void)tap:(UITapGestureRecognizer *)tgr{ 26 //手势所在的视图 27 //UIView * view = tgr.view; 28 NSLog(@"图片被单击了..."); 29 } 30 31 //双击手势事件 32 -(void)doubleTap:(UITapGestureRecognizer *)doubletgr{ 33 NSLog(@"图片被双击了..."); 34 }