iOS常用手势识别器
手势识别状态:
typedef NS_ENUM(NSInteger, UIGestureRecognizerState) {
// 没有触摸事件发生,所有手势识别的默认状态
UIGestureRecognizerStatePossible,
// 一个手势已经开始但尚未改变或者完成时
UIGestureRecognizerStateBegan,
// 手势状态改变
UIGestureRecognizerStateChanged,
// 手势完成
UIGestureRecognizerStateEnded,
// 手势取消,恢复至Possible状态
UIGestureRecognizerStateCancelled,
// 手势失败,恢复至Possible状态
UIGestureRecognizerStateFailed,
// 识别到手势识别
UIGestureRecognizerStateRecognized = UIGestureRecognizerStateEnded
};
需要同时支持多种手势时实现delegate方法,返回YES,可判断几种手势同时进行
// 该方法返回的BOOL值决定了view是否能够同时响应多个手势
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer
{
NSLog(@"%@ - %@", gestureRecognizer.class, otherGestureRecognizer.class);
return YES;
}
1.点击识别器
// 创建点击手势识别器,并监听
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapTouch)];
// 设置手势识别器属性
// 点击几次响应
tap.numberOfTapsRequired = 2;
// 几个手指同时点击
tap.numberOfTouchesRequired = 2;
// 添加手势识别器
[self.uiimageView addGestureRecognizer:tap];
2.长按识别器
// 创建长按识别器,并监听
UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(LongPressTouch)];
// 设置属性
// 多长时间响应
longPress.minimumPressDuration = 5;
// 按下后事件响应之前允许手指移动偏移位
longPress.allowableMovement = 10;
// 添加识别器
[self.view1 addGestureRecognizer:longPress];
3.轻扫
// 支持的手势方向枚举类型
typedef NS_OPTIONS(NSUInteger, UISwipeGestureRecognizerDirection) {
UISwipeGestureRecognizerDirectionRight = 1 << 0, // 向右
UISwipeGestureRecognizerDirectionLeft = 1 << 1, // 向左
UISwipeGestureRecognizerDirectionUp = 1 << 2, // 向上
UISwipeGestureRecognizerDirectionDown = 1 << 3 // 向下
};
// 创建轻扫识别器,并监听如果要同时使用多个方向,分别创建多个轻扫识别器
// 例:添加向左向右手势
// 向左
UISwipeGestureRecognizer *swipe = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(SwipehTouch)];
swipe.direction = UISwipeGestureRecognizerDirectionLeft;
[self.view1 addGestureRecognizer:swipe];
// 向右
UISwipeGestureRecognizer *swipe2 = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(SwipehTouch)];
swipe2.direction = UISwipeGestureRecognizerDirectionRight;
[self.view1 addGestureRecognizer:swipe2];
/**
* 旋转、捏合和拖拽注意点:当手指松开后会重置值,如果需要进行缩放旋转等操作,需在适当地方给返回的值赋值
*/
4.旋转
// 创建旋转识别器,并监听
UIRotationGestureRecognizer *rotation = [[UIRotationGestureRecognizer alloc] initWithTarget:self action:@selector(RotationTouch:)];
[self.view1 addGestureRecognizer:rotation];
// 注意点
- (void)RotationTouch:(UIRotationGestureRecognizer *)routation
{
NSLog(@"旋转");
// 每次加上之前的角度
self.view1.transform = CGAffineTransformRotate(self.view1.transform, routation.rotation);
// 将旋转角度清0
routation.rotation = 0;
}
5.捏合
// 创建捏合手势
UIPinchGestureRecognizer *pinch = [[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(pinchTouch:)];
[self.view1 addGestureRecognizer:pinch];
// 注意点
- (void)pinchTouch:(UIPinchGestureRecognizer *)pinch
{
NSLog(@"捏合");
self.view1.transform = CGAffineTransformScale(self.view1.transform, pinch.scale, pinch.scale);
pinch.scale = 1.0;
}
6.拖拽
// 创建拖拽手势
UIPanGestureRecognizer *pan = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(PanTouch)];
[self.view1 addGestureRecognizer:pan];
// 注意点
- (void)PanTouch:(UIPanGestureRecognizer *)pan
{
// 获取移动的坐标
CGPoint point = [pan translationInView:pan.view];
NSLog(@"拖拽");
CGPoint temp = self.view1.center;
temp.x += point.x;
temp.y += point.y;
self.view1.center = temp;
// 必须加
[pan setTranslation:CGPointZero inView:pan.view];
}
DEMO 链接: http://pan.baidu.com/s/1qW3VmUg 密码: 9pqk
转载于:https://www.cnblogs.com/miaomiaoshen/p/5188623.html
iOS常用手势识别器相关推荐
- iOS开发——手势识别器(用手势实现图片旋转和缩小放大)
iOS开发中,除了有关触摸的这组方法来控制用户的手指触控外,还可以用UIGestureRecognize的衍生类来进行判断,方便了开发. UIGestureRecognize的子类类别有以下几种: U ...
- iphonex如何关机_iphonex常用手势操作有哪些 iphonex常用手势操作介绍【详解】
iphonex常用手势操作有什么?相信小伙伴们一定很好奇,下面小编为大家带来了iphonex常用手势操作大全一览,感兴趣的小伙伴赶紧跟着小编一起来看看吧. 如何唤醒Siri 苹果一直追求极简的设计思路 ...
- ios pan手势滑动消失动画_IOS UIPanGestureRecognizer手势使用及识别状态UIGestureRecognizerState...
UIGestureRecognizerState -- 手势识别器状态 1.先来看官方文档 定义UIGestureRecognizer.h 英文: typedef NS_ENUM(NSInteger, ...
- ios各种手势,很有意思
转自http://blog.csdn.net/likendsl/article/details/7554150 这哥们很厉害的 一.概述 iPhone中处理触摸屏的操作,在3.2之前是主要使用的是由U ...
- python手势识别控制幻灯片翻页系统_实战1.2-利用手势识别器,实现视图的手势控制...
title: 实战1.2-利用手势识别器,实现视图的手势控制 知识预备 什么是仿射变换? 从视觉效果上来理解,仿射变换是通过一系列原子变换复合而来的变换.包括:平移(Translation).缩放(S ...
- UI一揽子计划 5 (Target: Action: 、Protocol Delegate、 UIImageView 、手势识别器)
一.target/ action 设计模式 耦合是衡量⼀一个程序写的好坏的标准之一, 耦合是衡量模块与模块之间关联程度的指标 "高内聚,低耦合"是⾯面 ...
- IOS常用正则表达式
IOS常用正则表达式 正则表达式用于字符串处理.表单验证等场合,实用高效.现将一些常用的表达式收集于此,以备不时之需. 匹配中文字符的正则表达式: [\u4e00-\u9fa5] 评注:匹配中文还真是 ...
- 154在屏幕中绘图时设置透明度(扩展知识:为图片视图添加点击手势识别器,来实现点击事件操作)...
一张图片,通过混合模式绘制后,能得到不同效果的图片. 这里的示例仅是测试效果:实际上可以通过不同程度的混合模式绘制,来得到符合需求的效果. 效果如下: ViewController.h 1 #impo ...
- iOS 九宫格手势密码
代码地址如下: http://www.demodashi.com/demo/11490.html 一.准备工作 需要准备什么环境 xcode,iOS8+ 本例子实现什么功能 主要实现手势密码设置,验证 ...
最新文章
- 5月.CN域名注册量持续上涨至1199万个 净增14万
- mysql添加临时索引_mysql创建索引/删除索引操作
- c#万能视频播放器 (转)
- Bootstrap全局css样式_表格
- Highcharts 本地导出图片 Java
- 一文搞清楚 Spark shuffle 调优
- qq代理服务器哪里获取_哪里可以下载小学英语课件?这3个渠道,英语老师得赶快收藏...
- 【kafka】JMX 监控kafka kafka rmi NoSuchObjectException no such object in table
- HR经常会用到的面试问题
- SVN的搭建(入门篇)
- 多线程—— Queue(储存进程结果)
- 公共网关接口CGI(Common GatewayInterface)
- php 调试环境配置
- Python深度学习(什么是深度学习)----学习笔记(一)
- 金蝶K3WISE盘点机PDA扫码入库仓库条码管理,外购入库单
- 计算机硬盘被配置成动态磁盘,动态硬盘
- zint编译配置整理
- 设置iPhone来电铃声(图文教程)
- Java联网3D坦克大战(网络编程)
- 恋与抽卡模拟器网页_《公主连结》抽卡模拟器网站是什么 抽卡模拟器地址介绍...
热门文章
- python 运维管理架构_企业运维监控平台架构设计与实现(ganglia篇)
- wordpress python 采集_Python3利用Selenium3模拟wordpress博客登陆
- python arp_用Python构造ARP请求、扫描、欺骗
- c++ 多个字符串排序_RPython Data Science系列:数据处理(5)--字符串函数基于R(一)
- httos双向认证配置_APP爬虫双向认证抓包的两种方法
- linux ls 时间显示时间格式,ls -l显示的日期格式如何设定?
- scp 上传文件到服务器
- php转型mysql dba_MySQL_DBA整理(转)
- Jdk8之Lambda表达式
- 相邻省份最多的省区_拉萨万达广场开业 实现中国大陆省份全覆盖