{
UIImageView *_imageView;
UITapGestureRecognizer *_tapOnce;
UITapGestureRecognizer *_tapTwice;
}
- (void)createImageView
{
_imageView = [[UIImageView alloc]init];
_imageView.frame = CGRectMake(40, 60, 300, 400);
_imageView.image = [UIImage imageNamed:@"17_13.jpg"];
//将imageview的可交互属性设置为yes
_imageView.userInteractionEnabled = YES;
[self.view addSubview:_imageView];
}
//2.创建手势方法
//2.1创建单击手势
- (void)createTapOnceGes
{
//参数1:处理手势的对象
//参数2:处理手势的方法
//这个对象处理的是点击手势
//该方法会讲手势中的view属性设置为_imageView
UITapGestureRecognizer *tapGes = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapOnceGes:)];
//设置当前手势需要点击的次数,1即为单击事件
tapGes.numberOfTapsRequired = 1;
//设置当前手势判定成功需要几个手指接触
tapGes.numberOfTouchesRequired = 1;
//在imageView视图上添加手势,添加了以后改视图就能识别和处理该手势
[_imageView addGestureRecognizer:tapGes];
}
//2.2创建双击手势
- (void)createTapTwiceGes
{
_tapTwice = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapTwiceGes:)];
_tapTwice.numberOfTapsRequired = 2;
_tapTwice.numberOfTouchesRequired = 1;
[_imageView addGestureRecognizer:_tapTwice];
//当双击事件无效时单击事件才有效
[_tapOnce requireGestureRecognizerToFail:_tapTwice];
}
//3.创建事件调用方法
//3.1单击事件方法
- (void)tapOnceGes:(UITapGestureRecognizer *)tapGes
{
_imageView.frame = self.view.bounds;
}
//3.2双击事件方法
- (void)tapTwiceGes:(UITapGestureRecognizer *)ges
{
_imageView.frame = CGRectMake(40, 60, 300, 400);
}