UITapGestureRecognizer给view添加手势事件

imageVIew.userInteractionEnabled=YES;

//图片view需要开启它的事件响应属性。其他的view默认是开启的。

//点击手势时间

//用来识别手势时间的

UITapGestureRecognizer* tapOne = [[UITapGestureRecognizeralloc]initWithTarget:selfaction:@selector(tapOneAct:)];

//手势识别类型表示几次点击时触发

tapOne.numberOfTapsRequired=2;

//表示几个手指点击时触发时事件

tapOne.numberOfTouchesRequired=1; //默认为1

[imageVIewaddGestureRecognizer:tapOne];

UITapGestureRecognizer* tapTwo = [[UITapGestureRecognizeralloc]initWithTarget:selfaction:@selector(tapTwoAct:)];

tapTwo.numberOfTapsRequired=1;

[imageVIewaddGestureRecognizer:tapTwo];

//表示当单击操作遇到双击操作时失效

[tapTworequireGestureRecognizerToFail:tapOne];

//事件中拿到触发事件的view

UIImageView* imageView = (UIImageView*) pinch.view;

你可能感兴趣的:(UITapGestureRecognizer给view添加手势事件)