手势

手势:

设置允许与用户交互

imageView.userInteractionEnabled=YES;

1.轻触手势:

创建对象时指定当手势被触发时由self调用action中的方法处理事件

UITapGestureRecognizer *tap=[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(handleTap:)];

设置需要轻按的次数

tap.numberOfTapsRequired=2;

设置需要轻按的手指数

tap.numberOfTouchesRequired=1;

将手势添加到图片视图上,

一个手势识别器只能添加到一个view上,一个view上可以添加多个手势识别器

[imageView addGestureRecognizer:tap];

2.移动手势

UIPanGestureRecognizer *pan=[[UIPanGestureRecognizer alloc]initWithTarget:self action:@selector(handlePan:)];

设置需要的最少手指数,默认是1

pan.minimumNumberOfTouches=1;

设置最多手指数

pan.maximumNumberOfTouches=2;

[imageView addGestureRecognizer:pan];

3.张合手势

UIPinchGestureRecognizer *pinch=[[UIPinchGestureRecognizer alloc]initWithTarget:self action:@selector(handlePinch:)];

[imageView addGestureRecognizer:pinch];

4.旋转手势

UIRotationGestureRecognizer *rotate=[[UIRotationGestureRecognizer alloc]initWithTarget:self action:@selector(handleRotation:)];

[imageView addGestureRecognizer:rotate];

5.轻划手势

UISwipeGestureRecognizer *swipe=[[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(handleSwipe:)];

[imageView2 addGestureRecognizer:swipe];

设置轻滑的方向

swipe.direction=UISwipeGestureRecognizerDirectionLeft;

当需要多个手势同时起作用时,需要设置代理 UIGestureRecognizerDelegate 并将代理交给视图本身

rotate.delegate=self;

pinch.delegate=self;

http://www.cnblogs.com/PaulpauL/ 版权声明:本文为博主原创文章,未经博主允许不得转载。
原文地址:https://www.cnblogs.com/PaulpauL/p/4935244.html