1.UITapGetureRecognizer的点击手势基本属性函数
numberOfTapsRequierd:点击次数
numberOfTouchRequired:点击手指个数
UIView:addGestureRecognizer 试图添加手势
requiredGestureRecognizerToFail手势失效函数
【ViewController.h】
#import<UIkit/UIkit.h>
@interface ViewController:UIViewController{
//定义视图对象
UIImageView*_imageView;
@edn
}
【ViewController.m】
#import"ViewController.h"
@interface Viewconroller()
@end
@implementation ViewController
-(void)viewDidLoad{
[supper viewDidLoad];
//加载图像对象,从本硬盘加载到内存中
UIImage* image=[[UIImage imageNamed:"17_2.jpg"];
//创建图像视图
_imageView=[[UIImage alloc]init];
//将图像视图的图像赋值
_imageView.image=image;
_imageView.frame=CGRectMake(50,80,200,300);
[self.view addSubview:_imageView];
//开启交互事件响应开关,YES:可以响应交互事件,NO :不能接实验室响应事件,默认值为:NO
_imageView.userInteractionEnabled=YES;
//创建一个点击手势对象,UITapGestureRecongnizer:点击手势,功能:识别点击手势事件,
//参数1:响应事件的拥有者对象,self表示当前视图控制器
//参数2:响应事件的函数
UITapGestureRecognizer* tapOneGes=[[UITapGesttureRecongnizer alloc]initWithTarget:self action:@selector(tapOneAct:]];
//表示手势识别事件的事件类型:几次点击的触发,/默认值为1
tapOneGest.numberOftapsRequired=1;
//青示几个手指点击时触发此事件函数,默认值为:1
tapOneGest.numberOfTouchesRequired=1;
//将点击事件添加到视图中,视图即可响应事件
[_imageView addGestureRecognizer:tapOnesGest];
//创建双击手势视图
UITapGestureRecognizer* tapOneGes=[[UITapGesttureRecongnizer alloc]initWithTarget:self action:@selector(tapTwo:]];
tapOneGest.numberOftapsRequired=2;
tapOneGest.numberOfTouchesRequired=1;
[_imageView addGestureRecognizer:tapTwot];
//当单击操作遇到双击操作时,单击操作失效
[tapOnesGes requireGestureRecognizerToFail:tapTwo];
}
-(void)tapTwo:(UITapGestureRecongnizer*)tap{
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuratin:1];
imageView.frame=CGRectMake(50,80,200,300);
[UIView commitAnimations];
}
//事件响应函数,参数手势点击事件对象
-(void)tapOneAct:(UITapGestureRecongnizer*)tap{
//获取手势监控的视图对象
UIImageView* imageView=(UIImageView*)tap.view;
//开始动画过程
[UIView beginAnimations:nil context:nil];
//设置动画过滤时间
[UIView setAnimationDuratin:2];
imageView.frame=CGRectMake(0,0320,568);
//结束动画过程
[UIView commitAnimations];
}
}