一、⼿势识别器
是对触摸事件做了封装,我们⽆需⾃⼰去判断某个⼿势 是否触发,⼿势识别器本⾝起到了识别作⽤,我们把重⼼放在识别之 后要做什么操作上⾯。
二、 七种手势识别器
1,轻拍手势识别器 UITapGestureRecognizer
2,我们不会直接使⽤⼿势识别器这个抽象⽗类,⽽是根据需要使⽤特定的⼿势识别器创建对象。
1)、创建UITapGestureRecognizer对象,使⽤initWithTarget:action:⽅法;
2)、配置要识别的⼿势的相关信息;
3)、将⼿势添加到某个视图上;
如:[imageView addGestureRecognizer:tap];
4)、实现⼿势识别器⾥定义的⽅法
获取当前手势放在哪一个view上 tap.view
三、 创建旋转手势
创建旋转手势
UIRotationGestureRecognizer *rotation = [[UIRotationGestureRecognizer alloc] initWithTarget:self action:@selector(doRotation:)];
[imageView addGestureRecognizer: rotation];
rotation.delegate = self;
[rotation release];
注意:
// 在做旋转的时候对应两个函数,一个是CGAffineTransformRotate(连续旋转),另一个是CGAffineTransformMakeRotation(做一次旋转)
// 在上次的基础上旋转
arotation.view.transform = CGAffineTransformRotate(arotation.view.transform, arotation.rotation);
// 让旋转角归零,下次在新角度下旋转,而不是累加
arotation.rotation = 0;
四、创建捏合手势
创建
// 创建捏合手势
UIPinchGestureRecognizer *pinch = [[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(doPinch:)];
[imageView addGestureRecognizer:pinch];
pinch.delegate = self;
[pinch release];
注意:
pinch.view.transform = CGAffineTransformScale(pinch.view.transform, pinch.scale, pinch.scale);
pinch.scale = 1;// 在原对象的基础上变化