- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
self.view.backgroundColor = [UIColor groupTableViewBackgroundColor]; _imageView = [[UIImageView alloc]initWithFrame:CGRectMake((self.view.frame.size.width-)/, (self.view.frame.size.height-)/, , )];
_imageView.userInteractionEnabled = YES;//交互使能,允许界面交互
_imageView.image = [UIImage imageNamed:@"cat.png"];
[self.view addSubview:_imageView]; // 单击的 TapRecognizer
UITapGestureRecognizer *singleTap;
singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(SingleTap:)];
singleTap.numberOfTapsRequired = ; //点击的次数 =1 单击 [_imageView addGestureRecognizer:singleTap];//给对象添加一个手势监测; // 双击的 TapRecognizer
UITapGestureRecognizer *doubleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(DoubleTap:)];
doubleTap.numberOfTapsRequired = ; //点击的次数 =2 双击
[_imageView addGestureRecognizer:doubleTap];//给对象添加一个手势监测; /*
1.双击手势确定监测失败才会触发单击手势的相应操作,否则双击时第一击时会响应单击事件
2.会造成单击时要判断是否是双击,调用单击会有所延时。属正常现象。
*/
[singleTap requireGestureRecognizerToFail:doubleTap]; //捏合缩放手势 Pinch
UIPinchGestureRecognizer *pinch;
pinch = [[UIPinchGestureRecognizer alloc]initWithTarget:self action:@selector(handlePinch:)];
// [_imageView addGestureRecognizer:pinch];//添加到_imageView的时候,是要把手指放到_imageView操作
[self.view addGestureRecognizer:pinch];//是self的时候,操作整个view都可以捏合_imageView(在响应事件中操作)
pinch.delegate = self; //旋转手势 Rotation
UIRotationGestureRecognizer *rotateRecognizer = [[UIRotationGestureRecognizer alloc]
initWithTarget:self
action:@selector(handleRotate:)];
[self.view addGestureRecognizer:rotateRecognizer];//是self的时候,操作整个view都可以捏合_imageView(在响应事件中操作)
rotateRecognizer.delegate = self; //滑动手势 SwipeRecognizer
UISwipeGestureRecognizer *swipeRecognizer = [[UISwipeGestureRecognizer alloc]
initWithTarget:self
action:@selector(handleSwipe:)];
[self.view addGestureRecognizer:swipeRecognizer];//是self的时候,操作整个view都可以捏合_imageView(在响应事件中操作)
swipeRecognizer.direction = UISwipeGestureRecognizerDirectionLeft;//操作为左滑
swipeRecognizer.delegate = self; //拖动手势 PanRecognizer
UIPanGestureRecognizer *panRecognizer = [[UIPanGestureRecognizer alloc]
initWithTarget:self
action:@selector(handlePan:)];
[_imageView addGestureRecognizer:panRecognizer];//关键语句,添加一个手势监测;
panRecognizer.maximumNumberOfTouches = ;
panRecognizer.delegate = self; //长按手势 LongPressRecognizer
UILongPressGestureRecognizer *longPressRecognizer = [[UILongPressGestureRecognizer alloc]
initWithTarget:self
action:@selector(handlelongPress:)];
[_imageView addGestureRecognizer:longPressRecognizer];
longPressRecognizer.minimumPressDuration = 1.0f;//触发长按事件时间为:1.0秒
longPressRecognizer.delegate = self; } -(void)SingleTap:(UITapGestureRecognizer*)recognizer
{
//处理单击操作
NSLog(@"单击操作");
} -(void)DoubleTap:(UITapGestureRecognizer*)recognizer
{
//处理双击操作
NSLog(@"双击操作");
} - (void)handlePinch:(UIPinchGestureRecognizer*)recognizer
{
NSLog(@"缩放操作");//处理缩放操作
//对imageview缩放
_imageView.transform = CGAffineTransformScale(_imageView.transform, recognizer.scale, recognizer.scale);
//对self.view缩放,因为recognizer是添加在self.view上的
//recognizer.view.transform = CGAffineTransformScale(recognizer.view.transform, recognizer.scale, recognizer.scale);
recognizer.scale = ;
} - (void)handleRotate:(UIRotationGestureRecognizer*) recognizer
{
NSLog(@"旋转操作");//处理旋转操作
//对imageview旋转
_imageView.transform = CGAffineTransformRotate(_imageView.transform, recognizer.rotation);
//对self.view旋转,因为recognizer是添加在self.view上的
// recognizer.view.transform = CGAffineTransformRotate(recognizer.view.transform, recognizer.rotation);
recognizer.rotation = ;
} - (void)handleSwipe:(UISwipeGestureRecognizer*) recognizer
{
//处理滑动操作
if(recognizer.direction==UISwipeGestureRecognizerDirectionLeft) {
NSLog(@"左滑滑动操作");
}else if(recognizer.direction==UISwipeGestureRecognizerDirectionRight){
NSLog(@"右滑滑动操作");
}
} -(void)handlePan:(UIPanGestureRecognizer*)recognizer
{
NSLog(@"拖动操作");
//处理拖动操作,拖动是基于imageview,如果经过旋转,拖动方向也是相对imageview上下左右移动,而不是屏幕对上下左右
CGPoint translation = [recognizer translationInView:_imageView];
recognizer.view.center = CGPointMake(recognizer.view.center.x + translation.x,
recognizer.view.center.y + translation.y);
[recognizer setTranslation:CGPointZero inView:_imageView];
} -(void)handlelongPress:(UILongPressGestureRecognizer*)recognizer
{
//处理长按操作,开始结束都会调用,所以长按1次会执行2次
if(recognizer.state == UIGestureRecognizerStateBegan){
NSLog(@"开始长按操作");
}else if(recognizer.state == UIGestureRecognizerStateEnded){
NSLog(@"结束长按操作");
}
} - (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}

UIGestureRecognizer 手势的更多相关文章

  1. 【学习总结】UIGestureRecognizer(手势识别器)

    基本知识点 : -> IOS 3.2之后 , 苹果推出了手势识别功能 ( Gesture Recognizer ) 在触摸事件处理方面 , 简化开发难度. -> UIGesture Rec ...

  2. UIGestureRecognizer 手势浅析

    目录[-] iOS开发中的手势体系——UIGestureRecognizer分析及其子类的使用 一.引言 二.手势的抽象类——UIGestureRecognizer 1.统一的初始化方法 2.手势状态 ...

  3. iOS边练边学--UIGestureRecognizer手势识别器简单介绍

    iOS 3.2之后,苹果退出了手势识别功能(Gesture Recognizer),在触摸事件处理方面,大大简化了开发者的开发难度. 一.UIGestureRecognizer UIGestureRe ...

  4. IOS 响应者链条 and UIGestureRecognizer 手势识别器)

    一次完整的触摸事件的传递响应的过程 UIAppliction --> UIWiondw -->递归找到最适合处理事件的控件 控件调用touches方法-->判断是否实现touches ...

  5. UIGestureRecognizer手势

    常用手势: 滑动,轻点,捏合,旋转,拖拽,长按 1.滑动(快速滑动) let swipeUp = UISwipeGestureRecognizer(target: self, action: Sele ...

  6. UI中的七种手势

    // // GestureRecognizerViewController.m #import "GestureRecognizerViewController.h" #impor ...

  7. iOS_38_手势

    Pan平移手势 终于效果图: Swipe轻扫手势 LongPress长按手势 Pinch和Rotation手势 捏合(缩放)和旋转 终于效果图: 涂鸦 终于效果图: 事件分3大类:触摸.加速计.远程遥 ...

  8. UI中各种手势的使用点击,捏合,清扫,旋转,平移,边缘移动,长按

    #import "RootViewController.h" @interface RootViewController (){    UIImageView *imageView ...

  9. DesignModeler GestureRecgin…

    DesignModeler : 设计模式     GestureRecginzer:手势识别 作者:韩俊强 原创版权地址:http://blog.sina.com.cn/s/blog_814ecfa9 ...

随机推荐

  1. 【串线篇】spring boot全面接管springMvc

    一.Spring MVC auto-configuration Spring Boot 自动配置好了SpringMVC 以下是SpringBoot对SpringMVC的默认配置:(WebMvcAutoC ...

  2. mysql 8.0.13 zip windows 10安装

    1.下载安装包 https://dev.mysql.com/downloads/mysql/ 下载后解压到D:\Program Files\mysql-8.0.13-winx64 2.添加配置文件my ...

  3. tuple写法

    name = ("wen") 类型为strname = ("wen",) 类型为tuple

  4. UML建模重点圈划

    面向对象的特征 *P9*>封装性>继承性>多态性>传递性 建模语言的三个类别 *P14*> - 非形式化的.半形式化的和形式化的 UML 特点*15*主要有三个特点:&g ...

  5. django 多条数据显示的坑(怪自己)

    今天的问题是,一个接口执行了很多次,每次都会在结果表里面记录一条结果信息,在查看接口详情页面,我想只展示一条,然后就进入误区了 第一个是怪自己手残,api_id  被自己写成app_id了 第二个是筛 ...

  6. sed 搜索并替换

    find . -type f -exec sed -i "s/std=c++11/std=c++14/g" {} \; 搜索当前目录下的文件,把std=c++11替换成std=c+ ...

  7. POJ 2449 Remmarguts' Date ( 第 k 短路 && A*算法 )

    题意 : 给出一个有向图.求起点 s 到终点 t 的第 k 短路.不存在则输出 -1 #include<stdio.h> #include<string.h> #include ...

  8. Strange fuction hdu 2899

    Strange fuction Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)T ...

  9. LintCode之加一

    题目描述: 分析:由样例可以知道,当数组的每一个数字都是9时,加一会产生一个最高位的数字1,所以先判断这个数组的每一位是否都是9,如果是,那么新数组的大小是原数组大小加一,否则新数组的大小等于原数组的 ...

  10. Layui数据表格/搜索重加载/分条件操作/工具条监听

    <div class="layui-layout layui-layout-admin" style="padding-left: 20px;"> ...