iOS开发中手势识别有六种:

轻击手势(TapGestureRecognizer),

轻扫手势 (SwipeGestureRecognizer),

长按手势(LongPressGestureRecognizer),

拖动手势(PanGestureRecognizer),

捏合手势(PinchGestureRecognizer),

旋转手势(RotationGestureRecognizer),

1,轻击手势(TapGestureRecognizer)

  1. UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapGesture:)];
  2. tapGesture.numberOfTapsRequired = 1; //点击次数
  3. tapGesture.numberOfTouchesRequired = 1; //点击手指数
  4. [self.view addGestureRecognizer:tapGesture];
  5.  
  6. //轻击手势触发方法
  7. -(void)tapGesture:(UITapGestureRecognizer *)sender
  8. {
  9. //your code
  10. }

2,长按手势(LongPressGestureRecognizer)

  1. UILongPressGestureRecognizer *longPressGesture = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longPressGesture:)];
  2. //设置长按时间
  3. longPressGesture.minimumPressDuration = 0.5;
  4. [self.view addGestureRecognizer:longPressGesture];
  5. //长按手势触发方法
  6. -(void)longPressGesture:(id)sender
  7. {
  8. UILongPressGestureRecognizer *longPress = sender;
  9. if (longPress.state == UIGestureRecognizerStateBegan)
  10. {
  11. //your code
  12. }
  13. }
  14. 说明:长按手势的常用状态如下
  15. 开始:UIGestureRecognizerStateBegan
  16. 改变:UIGestureRecognizerStateChanged
  17. 结束:UIGestureRecognizerStateEnded
  18. 取消:UIGestureRecognizerStateCancelled
  19. 失败:UIGestureRecognizerStateFailed

3,轻扫手势(SwipeGestureRecognizer)

  1. UISwipeGestureRecognizer *swipeGesture = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeGesture:)];
  2. //设置轻扫的方向
  3. swipeGesture.direction = UISwipeGestureRecognizerDirectionRight; //向右
  4. [self.view addGestureRecognizer:swipeGesture];
  5. UISwipeGestureRecognizer *swipeGestureLeft = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeGesture:)];
  6. //设置轻扫的方向
  7. swipeGestureLeft.direction = UISwipeGestureRecognizerDirectionLeft; //向左
  8. [self.view addGestureRecognizer:swipeGestureLeft];
  9. //轻扫手势触发方法
  10. -(void)swipeGesture:(id)sender
  11. {
  12. UISwipeGestureRecognizer *swipe = sender;
  13. if (swipe.direction == UISwipeGestureRecognizerDirectionLeft)
  14. {
  15. //向左轻扫
  16. }
  17. if (swipe.direction == UISwipeGestureRecognizerDirectionRight)
  18. {
  19. //向右轻扫
  20. }
  21. }

4,捏合手势(PinchGestureRecognizer)

  1. UIPinchGestureRecognizer *pinchGesture = [[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(pinchGesture:)];
  2. [self.view addGestureRecognizer:pinchGesture];
  3. ////捏合手势触发方法
  4. -(void) pinchGesture:(id)sender
  5. {
  6. UIPinchGestureRecognizer *gesture = sender;
  7. //手势改变时
  8. if (gesture.state == UIGestureRecognizerStateChanged)
  9. {
  10. //捏合手势中scale属性记录的缩放比例
  11. _imageView.transform = CGAffineTransformMakeScale(gesture.scale, gesture.scale);
  12. }
  13. //结束后恢复
  14. if(gesture.state==UIGestureRecognizerStateEnded)
  15. {
  16. [UIView animateWithDuration:0.5 animations:^{
  17. _imageView.transform = CGAffineTransformIdentity;//取消一切形变
  18. }];
  19. }
  20. }

5,拖动手势(PanGestureRecognizer)

  1. UIPanGestureRecognizer *panGesture = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(panGesture:)];
  2. [self.view addGestureRecognizer:panGesture];
  3.  
  4. //拖动手势触发方法
  5. -(void) panGesture:(id)sender
  6. {
  7. UIPanGestureRecognizer *panGesture = sender;
  8. CGPoint movePoint = [panGesture translationInView:self.view];
  9. //your code
  10. }

6,旋转手势(RotationGestureRecognizer)

  1. UIRotationGestureRecognizer *rotationGesture = [[UIRotationGestureRecognizer alloc] initWithTarget:self action:@selector(rotationGesture:)];
  2. [self.view addGestureRecognizer:rotationGesture];
  3. //旋转手势触发方法
  4. -(void)rotationGesture:(id)sender
  5. {
  6. UIRotationGestureRecognizer *gesture = sender;
  7. if (gesture.state==UIGestureRecognizerStateChanged)
  8. {
  9. _imageView.transform=CGAffineTransformMakeRotation(gesture.rotation);
  10. }
  11. if(gesture.state==UIGestureRecognizerStateEnded)
  12. {
  13. [UIView animateWithDuration:1 animations:^{
  14. _imageView.transform=CGAffineTransformIdentity;//取消形变
  15. }];
  16. }
  17. }

iOS开发中六种手势识别的更多相关文章

  1. 总结iOS开发中的断点续传那些事儿

    前言 断点续传概述 断点续传就是从文件赏赐中断的地方重新开始下载或者上传数据,而不是从头文件开始.当下载大文件的时候,如果没有实现断点续传功能,那么每次出现异常或者用户主动的暂停,都会从头下载,这样很 ...

  2. iOS开发中静态库之".framework静态库"的制作及使用篇

    iOS开发中静态库之".framework静态库"的制作及使用篇 .framework静态库支持OC和swift .a静态库如何制作可参照上一篇: iOS开发中静态库之" ...

  3. iOS开发中静态库制作 之.a静态库制作及使用篇

    iOS开发中静态库之".a静态库"的制作及使用篇 一.库的简介 1.什么是库? 库是程序代码的集合,是共享程序代码的一种方式 2.库的类型? 根据源代码的公开情况,库可以分为2种类 ...

  4. ios开发中的小技巧

    在这里总结一些iOS开发中的小技巧,能大大方便我们的开发,持续更新. UITableView的Group样式下顶部空白处理 //分组列表头部空白处理 UIView *view = [[UIViewal ...

  5. IOS 开发中 Whose view is not in the window hierarchy 错误的解决办法

    在 IOS 开发当中经常碰到 whose view is not in the window hierarchy 的错误,该错误简单的说,是由于 "ViewController" ...

  6. [转]iOS开发中的火星坐标系及各种坐标系转换算法

     iOS开发中的火星坐标系及各种坐标系转换算法 源:https://my.oschina.net/u/2607703/blog/619183   其原理是这样的:保密局开发了一个系统,能将实际的坐标转 ...

  7. iOS开发中常见问题集锦

    在iOS开发中,会出现各种各样的问题.今天,就把这些常见的问题以及各位大牛的解决方案汇总下,方便以后查阅: 常见错误: 1. linker command failed with exit code ...

  8. iOS开发中获取WiFi相关信息

    iOS 开发中难免会遇到很多与网络方面的判断,这里做个汇总,大多可能是与WiFi相关的. 1.Ping域名.Ping某IP 有 时候可能会遇到ping 某个域名或者ip通不通,再做下一步操作.这里的p ...

  9. iOS开发中设置UITextField的占位文字的颜色,和光标的颜色

    在iOS开发中,对于很多初学者而言,很有可能碰到需要修改UITextField的占位文字的颜色,以及当UITextField成为第一响应者后光标的颜色,那么下面小编就介绍一下修改占位文字和光标的颜色. ...

随机推荐

  1. TIF转JPG

    public void TifToJpg(string tifPath, string tifName) { try { //找到后缀为TIF的图像,如果没有,就catch退出 int len = t ...

  2. Python -- 函数之推导式

    5.12 推导式 l = [] for i in range(1,11): l.append(i) print(l) # 用列表推导式 (一行搞定) l = [i for i in range(1,1 ...

  3. JQuery EasyUI学习记录(一)

    1.主页设计(JQuery EasyUI插件) 下载easyUI开发包: 将easyUI资源文件导入页面中: <link rel="stylesheet" type=&quo ...

  4. HTML5中Web存储

    HTML5 中web存储是一个比cookies更好的一个本地存储方式. 那么什么是HTML5存储呢? 使用HTML5可以在本地存储用户浏览的数据,HTML5技术没有出来之前是使用cookies进行本地 ...

  5. webservice基础

    一.webservice概念 webservice用于异构平台之间的交互,我用Java写的程序,可以用php..net.pythod等其它语言的程序来访问我的接口.webservice有很多框架帮我们 ...

  6. 空类生成对象输出的结果是什么? toString()输出 覆写Object toString()方法输出的结果是什么

    空类生成对象输出的结果是什么? 输出的是对象在内存空间地址的哈希值 com.swift.P@1db9742 空类生成对象toString()输出的结果是什么? 输出的是对象在内存空间地址的哈希值的字符 ...

  7. NSCharacterSet去除字符串中的空格、删除指定\任意字符集

    一.去除首尾的空格 /** 1.去除首尾的空格*/ NSString *strMsg=@" 简书作者:CoderZb "; NSString *strResult = [strMs ...

  8. Unity3d 判断物体是否在可见范围内

    unity中自带两个回调函数: void OnBecameVisible()//当物体可见时,回调一次. void OnBecameInvisible()//当物体不可见时,回调一次. 在untiy编 ...

  9. sqlserver的实例名忘记了

    电脑图标右击/管理/服务和应用程序/服务 也可以直接services.msc打开 打开服务,找到sqlserver的服务,这个服务括号中的名称就是实例名了,但是要加上localhost,也就是loca ...

  10. shell 练习题

    1.编写脚本/bin/per.sh,判断当前用户对指定参数文件,是否不可读并且不可写 read -p "Please Input A File: " file if [ ! -e ...