ref:http://blog.csdn.net/rechard_chen/article/details/51769972
//点按手势的创建,这里需要实现响应事件的方法
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tap)];
tap.delegate = self;
// 添加到需要手势的视图
[_imageView addGestureRecognizer:tap];
// 长按 手势的创建
// 长按手势时间比较长,可以根据手势的状态states,设置功能;
UILongPressGestureRecognizer*longPres = [[UILongPressGestureRecognizer alloc]initWithTarget:self action:@selector(longPress:)];
[_imageView addGestureRecognizer:longPres];
// 添加 轻扫手势, 轻扫默认的方向:向右
// 一个轻扫手势只能支持一个方向
// 一个控件可以添加很多手势
UISwipeGestureRecognizer*swipeLeft = [[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(swipe:)]; //在响应方法中,可以根据轻扫的方向(direction)做事情;
//这是一个枚举类型,上下左右;
swipeLeft.direction= UISwipeGestureRecognizerDirectionLeft;
[_imageView addGestureRecognizer:swipeLeft];
UISwipeGestureRecognizer*swipeRight = [[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(swipe:)];
swipeRight.direction= UISwipeGestureRecognizerDirectionRight;
[_imageView addGestureRecognizer:swipeRight];
//拖拽手势的创建
UIPanGestureRecognizer *pan = [[ UIPanGestureRecognizer alloc ] initWithTarget : self action : @selector (pan:)];
[_imageView addGestureRecognizer:pan];
- ( void )pan:( UIPanGestureRecognizer *)pan
{
// 获取手指偏移量,相对于最原始位置的偏移量
CGPoint transP = [pantranslationInView:_imageView];
// 改 imageView 形变
_imageView.transform= CGAffineTransformTranslate(_imageView.transform, transP.x, transP.y);
// 复位,相对于上一次
[pansetTranslation:CGPointZeroinView:_imageView];
}
//在使用模拟器模拟一下两个手势的时候,需要按住option + 鼠标左键实现两个手指点击(反向运动);shift + option + 鼠标左键(同向运动);
//旋转手势的创建
UIRotationGestureRecognizer *rotation = [[ UIRotationGestureRecognizer alloc ] initWithTarget : self action :@selector (rotation:)];
rotation.delegate= self;
[_imageView addGestureRecognizer:rotation];
//方法的实现
- ( void )rotation:( UIRotationGestureRecognizer *)rotationGestureRecognizer
{
_imageView . transform = CGAffineTransformRotate ( _imageView . transform , rotationGestureRecognizer. rotation);
// 复位
rotationGestureRecognizer.rotation = 0;
}
//捏合缩放手势的实现
UIPinchGestureRecognizer *pinch = [[ UIPinchGestureRecognizer alloc ] initWithTarget : self action : @selector(pinch:)];
pinch.delegate= self;
[_imageView addGestureRecognizer:pinch];
//响应方法的实现
- ( void )pinch:( UIPinchGestureRecognizer *)pinch
{
// 获取相对于最原始的缩放比例
CGFloat scale = pinch.scale;
// x,y , x 表示宽度缩放多少, y 表示高度缩放
_imageView . transform = CGAffineTransformScale ( _imageView . transform , scale, scale);
// 复位
pinch.scale = 1;
}
手势代理方法的实现:
//当View需要同时实现多个手势的时候。需要返回YES;
- ( BOOL )gestureRecognizer:( UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:( UIGestureRecognizer *)otherGestureRecognizer;
//可以控制点击区域是否实现手势;通过UITouch获取当前点击的点,通过坐标控制区域
- ( BOOL )gestureRecognizer:( UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:( UITouch *)touch;
- iOS七大手势之(平移、捏合、轻扫、屏幕边缘轻扫)手势识别器方法
使用手势很简单,分为两步: 创建手势实例.当创建手势时,指定一个回调方法,当手势开始,改变.或结束时,回调方法被调用. 添加到需要识别的View中.每个手势只对应一个View,当屏幕触摸在View的边 ...
- iOS 手势操作:拖动、捏合、旋转、点按、长按、轻扫、自定义
1.UIGestureRecognizer 介绍 手势识别在 iOS 中非常重要,他极大地提高了移动设备的使用便捷性. iOS 系统在 3.2 以后,他提供了一些常用的手势(UIGestureReco ...
- iOS手势操作,拖动,轻击,捏合,旋转,长按,自定义(http://www.cnblogs.com/huangjianwu/p/4675648.html)
1.UIGestureRecognizer 介绍 手势识别在 iOS 中非常重要,他极大地提高了移动设备的使用便捷性. iOS 系统在 3.2 以后,他提供了一些常用的手势(UIGestureReco ...
- IOS 长按+轻扫(手势识别)
@interface NJViewController () @property (weak, nonatomic) IBOutlet UIView *customView; @end @implem ...
- iOS 七大手势之轻拍,长按,旋转手势识别器方法
一.监听触摸事件的做法 如果想监听一个view上面的触摸事件,之前的做法通常是:先自定义一个view,然后再实现view的touches方法,在方法内部实现具体处理代码 通过touches方法监听 ...
- iOS 七大手势之轻拍,长按,旋转手势识别器方法-赵小波
一.监听触摸事件的做法 如果想监听一个view上面的触摸事件,之前的做法通常是:先自定义一个view,然后再实现view的touches方法,在方法内部实现具体处理代码 通过touches方法监听vi ...
- iOS手势识别的详细使用(拖动,缩放,旋转,点击,手势依赖,自定义手势)
iOS手势识别的详细使用(拖动,缩放,旋转,点击,手势依赖,自定义手势) 1.UIGestureRecognizer介绍 手势识别在iOS上非常重要,手势操作移动设备的重要特征,极大的增加 ...
- ios iOS手势识别的详细使用(拖动,缩放,旋转,点击,手势依赖,自定义手势)
iOS手势识别的详细使用(拖动,缩放,旋转,点击,手势依赖,自定义手势) 转自容芳志大神的博客:http://www.cnblogs.com/stoic/archive/2013/02/27/2940 ...
- iOS,手势识别简单使用
1.iOS目前支持的手势识别(6种) 2.点按手势和慢速拖动手势简单使用 iOS目前支持的手势识别(6种) UITapGestureRecognizer(点按) UIPinchGestureRecog ...
随机推荐
- Node.js学习 - File Operation
同步异步 文件系统(fs 模块)模块中的方法均有异步和同步版本,例如读取文件内容的函数有异步的 fs.readFile() 和同步的 fs.readFileSync(). 异步的方法函数最后一个参数为 ...
- Python文件打包成EXE文件
工具:pyinstaller 安装:pip install pyinstaller 使用: 1 将依赖文件集中到一个文件夹: pyinstaller -D -w xxx.py ...
- PAT (Advanced Level) 1104. Sum of Number Segments (20)
简单题. #include<cstdio> #include<cstring> #include<cmath> #include<vector> #in ...
- LoadRunner监控Unix、Windows方法及常用性能指标
目 录 一.LoadRunner监控Linux资源.... 3 (一).准备工作... 3 1.可以通过两种方法验证服务器上是否配置了rstatd守护程序:... 3 (2)使用find命令... ...
- Zend Optimizer not installed可能原因及解决方法
Zend Optimizer not installed可能原因及解决方法 Optimizer, Zend 在配置php服务器的时候,所有的东西都安装好了,就是浏览一个要求zend的程序的时候,总是提 ...
- SORT函数的使用方法(转载)
sort函数的用法(转载出处:http://blog.sina.com.cn/s/blog_6439f26f01012xw3.html) 做ACM题的时候,排序是一种经常要用到的操作.如果每次都自己写 ...
- C++调用java
摘要: 1 java类生成c头文件和库文件 2 对于c/c++程序,启动时先启动jvm,然后获得对应的java类的对象和方法.然后正常使用. 最近正在做一个C/C++调用java的程序,这里说的调用j ...
- redis 持久化与备份策略 【转载】
本文转载自 http://blog.csdn.net/is_zhoufeng/article/details/10210353 持久化(persistence) 本文是 Redis 持久化文档 的中文 ...
- jquery控制audio的播放与暂停
<audio id="audio" src='music.mp3'></audio> <script type="type/javascri ...
- 深入浅出Ajax(三)
<html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> &l ...