单击
1.1初始化以及使用:
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapAction:)];
设置点击手指的个数
tap.numberOfTouchesRequired = 1;
// 设置手指点击的个数
tap.numberOfTapsRequired = 1;
[self.view addGestureRecognizer:tap];
点击触发的方法:
- (void) tapAction:(UITapGestureRecognizer *) sender{
// self.view.backgroundColor = [UIColor brownColor];
iamgeView.transform = CGAffineTransformIdentity;
CGPoint point = [sender locationInView:self.view];
[UIView animateWithDuration:0.5 animations:^{
iamgeView.center = point;
}];
}
1.2 长按
1.2.1:初始化以及使用:
UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc]initWithTarget: self action:@selector( longpress: )];
longPress.minimumPressDuration = 0.5;
[self.view addGestureRecognizer: longPress];
长按触发的方法:
- (void) longPress:(UILongPressGestureRecognizer *)longPress
{
// iamgeView.center = CGPointMake(20, 20);
// 获得手势的触摸点
CGPoint point = [longPress locationInView:self.view];
NSLog(@"%f %f",point.x,point.y);
[UIView animateWithDuration:0.2 animations:^{
iamgeView.center = point;
}];
}
拖拽
1.初始化以及使用:
UIPanGestureRecognizer *pan = [[UIPanGestureRecognizer alloc] initWithTarget: self action: @selector (panAction:)];
pan.miniNumberOfTouches = 1;
[self.view addGestureRecognizer: pan];
拖拽触发的方法:
- (void) panAction:(UIPanGestureRecognizer *) sender{
// 获取位置信息
CGPoint point = [sender locationInView:self.view];
iamgeView.center = point;
}
清扫
1.初始化以及使用
UISwipeGestureRecognizer *swipe = [[UISwipeGestureRecognizer alloc]initWithTarget: self action: @selector ( swipe: )];
swipe.direction = UISwipeGestureRecognizerDirectionLeft;
[pan requireGestureRecognizerToFail:swipe];
用来处理拖拽和清扫手势的冲突,判断哪个手势时间段,就让哪个手势先执行
[self.view addGestureRecognizer:swipe];
拖拽触发的方法:
- (void) swipe:(UISwipeGestureRecognizer *)sender{
self.view.frame = CGRectMake(CGRectGetWidth([UIScreen mainScreen].bounds), 0, CGRectGetWidth([UIScreen mainScreen].bounds), CGRectGetHeight([UIScreen mainScreen].bounds));
[UIView animateWithDuration:1 animations:^{
self.view.frame = CGRectMake(0, 0, CGRectGetWidth([UIScreen mainScreen].bounds), CGRectGetHeight([UIScreen mainScreen].bounds));
}];
}
捏合
UIPichGestureRecognizer *pich = [ [UIPichGestureRecognizer alloc] initWithTarget: self action: @selector (pichAction:)];
[self.view addGestureRecognizer:pich];
捏合触发的方法:
- (void) pichAction:(UIPinchGestureRecognizer *)sender{
// 通过手势得到的 变化比例 让imageView的形态发生改变
iamgeView.transform = CGAffineTransformScale(iamgeView.transform, sender.scale, sender.scale);
}
旋转
1.初始化以及使用:
UIRotationGestureRecognizer *rotation = [[UIRotationGestureRecognizer alloc] initWithTarget: self action: @selector(retationAction:)];
[self.view addGestureRecognizer: rotation];
旋转触发的方法:
- (void) rotationAction:(UIRotationGestureRecognizer *)sender{
iamgeView.transform = CGAffineTransformMakeRotation(sender.rotation);
}