UIGesture

来源:互联网 发布:写小说 网站 知乎 编辑:程序博客网 时间:2024/05/03 23:29

UITapGestureRecognizer 点击手势
1、实例化
UITapGestureRecognizer* tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(imageViewTap
2、将手势添加到视图
[imageView addGestureRecognizer:tap];
3、设置点击次数(只有tap才有)
tap.numberOfTapsRequired = 2;
4、设置手指数
tap.numberOfTouchesRequired = 2;
UILongPressGresstureRecognize 长按手势
1、实例化
UILongPressGestureRecognizer* longPress = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longPressClick:)];
2、最短长按时间
longPress.minimumPressDuration = 2;
3、允许滑动范围
longPress.allowableMovement = 50;
4、视图添加手势
[imageView addGestureRecognizer:longPress];
UISwipeGestureRecognizer 滑动手势
1、实例化
UISwipeGestureRecognizer* swipe1 = [[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(swipeView:)];
2、滑动方向
swipe1.direction = UISwipeGestureRecognizerDirectionRight;
3、添加手势
[imageView addGestureRecognizer:swipe1];
UIPanGestureRecognizer 移动手势
1、实例化
UIPanGestureRecognizer* pan = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(panClick:)];
2、添加手势
[imageView addGestureRecognizer:pan];
UIPinchGestureRecognizer 缩放手势
1、实例化
UIPinchGestureRecognizer* pinch = [[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(pinchClick:)];
2、添加手势
[imageView addGestureRecognizer:pinch];
UIRotationGestureRecognizer 旋转手势
1、实例化
UIRotationGestureRecognizer* ratotion = [[UIRotationGestureRecognizer alloc] initWithTarget:self action:@selector(rotationClick:)];
2、添加手势
[imageView addGestureRecognizer:ratotion];
手势的代理方法
//在一个视图上可以执行不同手势的方法
- (BOOL)gestureRecognizer:(UIGestureRecognizer )gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer )otherGestureRecognizer{
return YES;
}

0 0
原创粉丝点击