清华大佬耗费三个月吐血整理的几百G的资源,免费分享!....>>>
/*********************滑动手势*************************/
//创建手势名数组
UISwipeGestureRecognizerDirection num[4] = {
UISwipeGestureRecognizerDirectionRight,
UISwipeGestureRecognizerDirectionLeft,
UISwipeGestureRecognizerDirectionUp,
UISwipeGestureRecognizerDirectionDown
};
//创建四个方向的滑动手势
for (int i = 0; i < 4; i++) {
//创建一个滑动手势
UISwipeGestureRecognizer *swipe = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipe:)];
swipe.direction = num[i];
//给当前界面增加滑动手势
[self.view addGestureRecognizer:swipe];
}
/*********************点击手势*************************/
//创建一个点击手势
UITapGestureRecognizer * tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tap:)];
//增加手势之后 一旦点击图片那么就会触发事件 self调用tap:
//点击手势的范围就在图片范围内
//设置点击的次数
//1.单击 2.双击
tap.numberOfTapsRequired = 2;
//设置手指个数
tap.numberOfTouchesRequired = 2;
// 按住option 就可以出现两个圆圈 表示两只手指
//给_imageView增加手势
UIImageView *imageView = [UIImageView new];
[imageView addGestureRecognizer:tap];
//获取手势所在视图
tap.UIView;
/*********************捏合手势*************************/
//创建一个捏合手势
UIPinchGestureRecognizer * pinch = [[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(pinch:)];
//手指收缩 缩小图片 放大的时候放大图片
_imageView.transform = CGAffineTransformScale(_imageView.transform, pinch.scale, pinch.scale);
//重新设置 手势比例
pinch.scale = 1;
/*********************旋转手势*************************/
//创建一个旋转手势
UIRotationGestureRecognizer * rotation = [[UIRotationGestureRecognizer alloc] initWithTarget:self action:@selector(rotation:)];
//根据手势的旋转弧度来改变
_imageView.transform = CGAffineTransformRotate(_imageView.transform, rotation.rotation);
//重新设置 手势比例
rotation.rotation = 0;
/*********************拖动手势*************************/
//创建一个旋转手势
UIPanGestureRecognizer * pan = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(pan:)];
//获取当前手势的偏移量(相对于某个视图的)
//手势 要和图片的参考物相同的
CGPoint offset = [pan translationInView:self.view];
//加上偏移量 那么图片跟手势一起移动
_imageView.center = CGPointMake(_imageView.center.x+offset.x, _imageView.center.y+offset.y);
//重新设置 偏移量//重置为0 (都要相对于当前的 下次要从0开始)
[pan setTranslation:CGPointZero inView:self.view];
/*********************长按手势*************************/
//创建一个旋转手势
UILongPressGestureRecognizer * longPress = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(press:)];
//长按手势会触发两次,无法设置是否触发,但可以在触发函内判断什么时候执行
//长按刚开始一次 长按结束的时候一次,并且在手指移动的时候每一栋一次触发一次
//长按手势刚开始的时候
press.state = UIGestureRecognizerStateBegan;
//手势结束的状态
press.state = UIGestureRecognizerStateEnded;
//手势改变
press.state = UIGestureRecognizerStateChanged;
/*********************是否允许两个手势同时有效*************************/
//(允许两个手势同时触发要遵守UIGestureRecognizerDelegate协议)
//需要同时生效的手势必须都要设置代理
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer{
return YES;
}