1、点击

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

    //设置当前需要点击的次数
[tap setNumberOfTapsRequired:];
//设置当前需要触发事件的手指数量
[tap setNumberOfTouchesRequired:];
//设置当前代理
tap.delegate=self;
[_view addGestureRecognizer:tap];
//触发方法
- (void) click{
NSLog(@"当前视图被点击了! ");
}

2、长按

UILongPressGestureRecognizer * longPress=[[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longPress)];
//设置当前长按最小的时长
longPress.minimumPressDuration=; //设置允许的移动范围
[longPress setAllowableMovement:];
[_view addGestureRecognizer:longPress];
//触发方法
- (void) longPress{
NSLog(@"长按事件触发! ");
}

3、轻扫

UISwipeGestureRecognizer * swip=[[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipMethod)];
//往左边方向
swip.direction=UISwipeGestureRecognizerDirectionLeft ;
//往右边方向
swip.direction=UISwipeGestureRecognizerDirectionRight ;
//往上面方向
swip.direction=UISwipeGestureRecognizerDirectionUp ;
//往下面方向
swip.direction=UISwipeGestureRecognizerDirectionDown ;
[_view addGestureRecognizer:swip]; //触发方法
- (void) swipMethod{
NSLog(@"轻扫事件触发! ");
}

  如果涉及到2个以上方向的手势最好添加多个UISwipeGestureRecognizer 对象并设置不同的方向,不要通过下面方式用符号|来连接:

swip.direction=UISwipeGestureRecognizerDirectionLeft  | UISwipeGestureRecognizerDirectionRight  

4、拖动

  第一步:添加视图

_view=[[UIView alloc] initWithFrame:CGRectMake(, , , )];
[_view setBackgroundColor:[UIColor redColor]];
[self.view addSubview:_view];

  第二步:添加手势

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

  第三步:实现方法

- (void) paned:(UIPanGestureRecognizer *) pan{

    //获取移动的大小
CGPoint point= [pan translationInView:pan.view];
//更改视图的中心点坐标
CGPoint points=_view.center;
points.x+=point.x;
points.y+=point.y;
_view.center=points;
//每次都清空一下消除坐标叠加
[pan setTranslation:CGPointZero inView:pan.view];
}

5、旋转

  第一步:添加视图

_view=[[UIView alloc] initWithFrame:CGRectMake(, , , )];
[_view setBackgroundColor:[UIColor redColor]];
[self.view addSubview:_view];

  第二步:添加手势

UIRotationGestureRecognizer * roate=[[UIRotationGestureRecognizer alloc] initWithTarget:self action:@selector(rotate:)];
[_view addGestureRecognizer:roate];
roate.delegate=self;

  第三步:实现方法

- (void) rotate:(UIRotationGestureRecognizer *) rote{
//获取当前旋转的度数
CGFloat rotation= rote.rotation;
//通过仿射变换实现旋转
_view.transform=CGAffineTransformRotate(_view.transform, rotation);
//防止旋转叠加需要清零
rote.rotation=;
}

6、捏合

  第一步:添加视图

_view=[[UIView alloc] initWithFrame:CGRectMake(, , , )];
[_view setBackgroundColor:[UIColor redColor]];
[self.view addSubview:_view];

  第二步:添加手势

UIPinchGestureRecognizer * pich=[[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(piches:)];
[_view addGestureRecognizer:pich];
pich.delegate=self;

  第三步:实现方法

- (void) piches:(UIPinchGestureRecognizer *) pich{
//获取比例
CGFloat scale=pich.scale;
//通过仿射变换实现缩放
_view.transform=CGAffineTransformScale(_view.transform, scale, scale);
//防止比例叠加需要置为1
pich.scale=;
}

【补充】如果需要同时响应多个手势需要重写代理方法

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer{
return YES;
}
作者:杰瑞教育
出处:http://www.cnblogs.com/jerehedu/ 
本文版权归烟台杰瑞教育科技有限公司和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。
 

IOS中的手势详解的更多相关文章

  1. iOS中—触摸事件详解及使用

    iOS中--触摸事件详解及使用 (一)初识 要想学好触摸事件,这第一部分的基础理论是必须要学会的,希望大家可以耐心看完. 1.基本概念: 触摸事件 是iOS事件中的一种事件类型,在iOS中按照事件划分 ...

  2. IOS中UITableViewCell使用详解

    IOS中UITableViewCell使用详解 - (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(N ...

  3. iOS中RSA加密详解

    先贴出代码的地址,做个说明,因为RSA加密在iOS的代码比较少,网上开源的也很少,最多的才8个星星.使用过程中发现有错误.然后我做了修正,和另一个库进行了整合,然后将其支持CocoaPod. http ...

  4. 在IOS中 NSRange类详解

    NSRange的定义 typedef struct _NSRange { NSUInteger location; NSUInteger length; } NSRange; NSRange是一个结构 ...

  5. iOS中 支付宝钱包详解/第三方支付 韩俊强的博客

    每日更新关注:http://weibo.com/hanjunqiang  新浪微博! iOS开发者交流QQ群: 446310206 一.在app中成功完成支付宝支付的过程 1.申请支付宝钱包.参考网址 ...

  6. iOS中 断点下载详解 韩俊强的博客

    布局如下: 基本拖拉属性: #import "ViewController.h" #import "AFNetworking.h" @interface Vie ...

  7. iOS中 百度地图详解 韩俊强的博文

    需要准备工作按照下图引进类库 需要添加 添加的两个字符串为:NSLocationWhenInUseUsageDescription  /  NSLocationAlwaysUsageDescripti ...

  8. iOS原生地图开发详解

    在上一篇博客中:http://my.oschina.net/u/2340880/blog/414760.对iOS中的定位服务进行了详细的介绍与参数说明,在开发中,地位服务往往与地图框架结合使用,这篇博 ...

  9. iOS 单元测试之XCTest详解(一)

    iOS 单元测试之XCTest详解(一) http://blog.csdn.net/hello_hwc/article/details/46671053 原创blog,转载请注明出处 blog.csd ...

随机推荐

  1. [leetcode sort]56. Merge Intervals

    Given a collection of intervals, merge all overlapping intervals. For example,Given [1,3],[2,6],[8,1 ...

  2. int类型的整数转换成汉字

    int类型的整数转换成汉字 一.源代码:IntegerNumberToChinese.java package cn.com.zfc.example; import java.util.Scanner ...

  3. BZOJ.5407.girls(容斥 三元环)

    题目链接 CF 原题 \(Description\) 有n个点,其中有m条边连接两个点.每一个没有连边的三元组\((i,j,k)(i<j<k)\)对答案的贡献为\(A*i+B*j+C*k\ ...

  4. BZOJ 3238 [Ahoi2013]差异(后缀自动机)

    [题目链接] http://www.lydsy.com/JudgeOnline/problem.php?id=3238 [题目大意] 给出一个串,设T[i]表示从第i位开始的后缀, 求sum(len( ...

  5. 用Win32编写发送消息至Notepad++的程序

    这次利用Win32编程写一个发送"Win32 Assembly,My First SendMessage Program !" 每个程序要发送消息至另一个程序的时候,通常使用Sen ...

  6. SpringBoot静态资源目录

    在web开发中,静态资源的访问是必不可少的,如:图片.js.css 等资源的访问. SpringBoot对静态资源访问提供了很好的支持,基本使用默认配置就能满足开发需求. 在传统的web项目中静态资源 ...

  7. 多线程_java多线程环境下栈信息分析思路

    导读:Java多线程开发给程序带来好处的同时,由于多线程程序导致的问题也越来越多,而且对问题的查找和分析解决对于菜鸟程序原来是是件头疼的事.下面我就项目中使用多线程开发程序过程中遇到的问题做详细的分析 ...

  8. 使用Bootstrap 3开发响应式网站实践03,轮播下方的内容排版

    通常把一些重要信息.需要重点标注的信息放在轮播的下方显示,这部分区域用到了大字体的标题.副标题以及段落文字等. <div class="row" id="bigCa ...

  9. 报错:405 Method Not Allowed

    出现错误的原因是:静态文件不能通过post方式访问. 解决办法:改成用get方式访问.

  10. SpringBoot 使用小技巧合集

    原文:https://my.oschina.net/xiedeshou/blog/1926191 设置网站图标 原来我们在使用tomcat开发时,设置网站图片时,即icon图标时,一般都是直接替换ro ...