UITapGestureRecognizer是没有tag属性,但他有UIView的属性,我们可以通过给UIView添加tag属性,从而标记UITapGestureRecognizer。
- (void)viewDidLoad {
[super viewDidLoad];
UITapGestureRecognizer* tap=[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tap:)];
self.view.tag=10;
[self.view addGestureRecognizer:tap];
}
-(void)tap:(UITapGestureRecognizer*) recognizer
{
UIView * view=recognizer.view;
NSLog(@"%ld",(long)view.tag);
}
下面的方法是区分不同手势绑定一个View
-(void)UIGestureRecognizer:(UIGestureRecognizer*) recognizer{
if([recognizer isKindOfClass:[UIPinchGestureRecognizer class]]){
}
else if([recognizer isKindOfClass:[UITapGestureRecognizer class]] ){
}else{
}}