#import "RootViewController.h"@interface RootViewController ()@end@implementation RootViewController- (void)viewDidLoad {[super viewDidLoad];// Do any additional setup after loading the view.self.view.backgroundColor = [UIColor redColor];// 创建一个imageViewUIImageView *imageView = [[UIImageView alloc] initWithFrame:[UIScreen mainScreen].bounds];imageView.image = [UIImage imageNamed:@"u=2473889012,1045156706&fm=21&gp=0.jpg"];//  UIImageView 默认交互是关闭的 ,所以需要打开imageView.userInteractionEnabled = YES;[self.view addSubview:imageView];[imageView release];// 手机识别器这个类 , 是一个抽象类// 自己本身不实现什么具体功能//具体功能都是由其子类来实现// 第一个:轻拍手势UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(actionTap:)];// 用 几个手指 轻拍tap.numberOfTouchesRequired = 2; // 默认是1// 轻拍的次数tap.numberOfTapsRequired = 1; // 默认是1// 把手势添加到要点击轻拍的视图上[imageView addGestureRecognizer:tap];[tap release];/*//第二个: 长按手势UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(actionLongPress:)];// 最短长按时间longPress.minimumPressDuration = 1;// 添加到视图上[imageView addGestureRecognizer:longPress];[longPress release];*//*// 第三个: 旋转手势UIRotationGestureRecognizer *rotation = [[UIRotationGestureRecognizer alloc] initWithTarget:self action:@selector(actionRotation:)];// 添加到视图上[imageView addGestureRecognizer:rotation];[rotation release];*//*// 第四个: 捏合手势UIPinchGestureRecognizer *pinch = [[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(actionPinch:)];// 直接添加到视图上[imageView addGestureRecognizer:pinch];[pinch release];*//*// 第五个 平移手势UIPanGestureRecognizer *pan = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(actionPan:)];// 添加到视图上[imageView addGestureRecognizer:pan];[pan release];*///    // 第六个 清扫手势
//    UISwipeGestureRecognizer *swipe = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(actionSwipe:)];
//    // 设置左右扫
//    swipe.direction = UISwipeGestureRecognizerDirectionLeft; // 默认是右扫
//
//    // 添加到视图上
//    [imageView addGestureRecognizer:swipe];
//    [swipe release];// 第七个: 边缘扫 是默认的 不设置也有边缘扫UIScreenEdgePanGestureRecognizer *screenEdgePan = [[UIScreenEdgePanGestureRecognizer alloc] initWithTarget:self action:@selector(actionScreenEdgePan:)];//  设置从屏幕边缘 那边去扫screenEdgePan.edges = UIRectEdgeLeft;[imageView addGestureRecognizer:screenEdgePan];[screenEdgePan release];}//1, 轻拍触发方法
- (void)actionTap:(UITapGestureRecognizer *)tap
{NSLog(@"轻拍了");
}
// 2,长按触发方法
- (void)actionLongPress:(UILongPressGestureRecognizer *)longPress
{// 长按 换图片// 获取到长按的viewUIImageView *imageView = (UIImageView *)longPress.view;imageView.image = [UIImage imageNamed:@"u=3484715933,459413563&fm=23&gp=0.jpg"];NSLog(@"长按手势实现");
}
// 3,旋转触发方法
- (void)actionRotation:(UIRotationGestureRecognizer *)rotation
{// transform 形变属性// 描述一下这个方法// 第一个参数 传入要创建那个视图的形变属性// 第二个参数 传入 手势的弧度rotation.view.transform = CGAffineTransformRotate(rotation.view.transform, rotation.rotation);// 把弧度重置rotation.rotation = 0;NSLog(@"旋转了");
}//4, 捏合触发方法
- (void)actionPinch:(UIPinchGestureRecognizer *)pinch
{// 形变属性控制 捏合// 第二个参数 按捏合的刻度比例 形变pinch.view.transform  = CGAffineTransformScale(pinch.view.transform, pinch.scale, pinch.scale);// 重置刻度比例pinch.scale = 1;NSLog(@"捏合手势");
}// 5. 平移触发方法
- (void)actionPan:(UIPanGestureRecognizer *)pan
{// 这个点 以手指触摸到屏幕那一刻 即为0,0点CGPoint p = [pan translationInView:pan.view];NSLog(@"%@", NSStringFromCGPoint(p));pan.view.transform = CGAffineTransformTranslate(pan.view.transform, p.x, p.y);// 重置 点 让他以为每次都是刚开始触发[pan setTranslation:CGPointMake(0, 0) inView:pan.view];//[pan translationInView:self.view];
}// 6. 左右扫触发方法
- (void)actionSwipe:(UISwipeGestureRecognizer *)swipe
{NSLog(@"左扫了");}// 7. 边缘扫触发方法
- (void)actionScreenEdgePan:(UIScreenEdgePanGestureRecognizer *)screenEdgePan
{// 刚一扫就触发if (screenEdgePan.state == UIGestureRecognizerStateBegan) {NSLog(@"边缘扫 左扫");}}

iOS疯狂讲解之手势识别器相关推荐

  1. iOS疯狂讲解之Xcode菜单及快捷键大全

    2.偏好设置 通过"command+,"快捷键或"Xcode|Preferences"菜单呼出偏好设置. (1)主题及字体(Preferences->Fo ...

  2. iOS开发——手势识别器(用手势实现图片旋转和缩小放大)

    iOS开发中,除了有关触摸的这组方法来控制用户的手指触控外,还可以用UIGestureRecognize的衍生类来进行判断,方便了开发. UIGestureRecognize的子类类别有以下几种: U ...

  3. iOS常用手势识别器

    手势识别状态: typedef NS_ENUM(NSInteger, UIGestureRecognizerState) { // 没有触摸事件发生,所有手势识别的默认状态 UIGestureReco ...

  4. iOS——6种系统手势操作

    UIGestureRecognizer(手势识别器) 手势识别在 iOS 中非常重要,他极大地提高了移动设备的使用便捷性. iOS 系统在 3.2 以后,他提供了六种常用的手势(UIGestureRe ...

  5. CALayer与iOS动画 讲解及使用

    iOS CALayer与iOS动画 讲解及使用 关于CoreAnimation 初识CALayer CALayer CAAnimation CAMediaTiming UIView与CALayer动画 ...

  6. python手势识别控制幻灯片翻页系统_实战1.2-利用手势识别器,实现视图的手势控制...

    title: 实战1.2-利用手势识别器,实现视图的手势控制 知识预备 什么是仿射变换? 从视觉效果上来理解,仿射变换是通过一系列原子变换复合而来的变换.包括:平移(Translation).缩放(S ...

  7. UI一揽子计划 5 (Target: Action:  、Protocol   Delegate、 UIImageView 、手势识别器)

    一.target/ action 设计模式      耦合是衡量⼀一个程序写的好坏的标准之一,      耦合是衡量模块与模块之间关联程度的指标      "高内聚,低耦合"是⾯面 ...

  8. 154在屏幕中绘图时设置透明度(扩展知识:为图片视图添加点击手势识别器,来实现点击事件操作)...

    一张图片,通过混合模式绘制后,能得到不同效果的图片. 这里的示例仅是测试效果:实际上可以通过不同程度的混合模式绘制,来得到符合需求的效果. 效果如下: ViewController.h 1 #impo ...

  9. IOS开发基础之手势解锁项目案例

    IOS开发基础之手势解锁项目案例 项目最终实现效果. 由于缺少红色的error背景图.我自己从安卓项目找到一个手势解锁,然后通过ps添加粉红色的红圈,才得以解决.为了分享给大家源码,github和本地 ...

最新文章

  1. 课题背景 一二三代测序技术
  2. python获取docx文档的内容(文本)
  3. mysql 5.7.11 my.ini,mysql5.7以上版本配置my.ini的详细步骤
  4. LeetCode 螺旋矩阵(Spiral Matrix)
  5. java中的%%%_JSP页面中%!%与%%与%=%
  6. 观察者模式及c++实现
  7. java基础篇---网络编程(IP与URL)
  8. 作业要求 20181023-3 每周例行报告
  9. Java集合---面试题
  10. Mac 本地搭建服务器实现itms-services方式安装ipa(自制证书)
  11. java wait 执行顺序_JAVA 的wait(), notify()与synchronized同步机制
  12. Oracle ~ 索引种类、创建及管理
  13. Wunderlist 云端任务管理(Todo list)工具
  14. 网络分析仪测试线损_网络分析仪测试天线隔离度
  15. QThread: Destroyed while thread is still running 解决方法
  16. 安装程序遇到错误:0x80240037 尝试打开时出错 - WSUSSCAN.cab 错误: 0x80070002。WSUSSCAN.cab文件 是什么?cab 是什么文件?
  17. webp怎么转png?图片webp格式怎么转换?
  18. 元胞自动机交通模型【matlab实现】
  19. 三角形面积外接圆内切圆
  20. 2022年四季度人力资源趋势报告

热门文章

  1. python抢红包程序算法,Python 抢红包算法模拟
  2. 成功需要培养独特的眼光,芸赞通天下沈杨
  3. SUST_2018 焦作站亚洲区域赛校内选拔赛题解
  4. Android异常之SIGABRT
  5. 基于功能的差异化战略
  6. 《软技能·代码之外的生存指南》读书笔记 ——自我营销
  7. java 坦克大战画坦克_Java坦克大战部分:画出界面,敌人坦克,我的坦克,不出界,键盘事件【诗书画唱】...
  8. ANSI标准数据类型
  9. 面试官:讲讲互斥锁、自旋锁吧
  10. python的re模块替换文件字符串_Python 正则处理_re模块