UIPanGestureRecognizer怎么用
来源:互联网 发布:linux的复制命令 编辑:程序博客网 时间:2024/04/30 11:50
废话少说 开始笔记
UIGestureRecognizer是一个定义基本手势的抽象类,具体什么手势,在以下子类中包含:
1、拍击UITapGestureRecognizer (任意次数的拍击)
2、向里或向外捏UIPinchGestureRecognizer (用于缩放)
3、摇动或者拖拽UIPanGestureRecognizer (拖动)
4、擦碰UISwipeGestureRecognizer (以任意方向)
5、旋转UIRotationGestureRecognizer (手指朝相反方向移动)
6、长按UILongPressGestureRecognizer (长按)
今天一同学问到UIPanGestureRecognizer类中translationInView方法和velocityInView方法有什么区别,因为我也好久没看IOS,一丢下就很难拾起,故今天研究下这个问题
UIPanGestureRecognizer主要用于拖动,比如桌面上有一张图片uiimageview,你想让它由原始位置拖到任何一个位置,就是图片跟着你的手指走动,那么就需要用到该类了。
以下代码表示给一个图片视图指定一个UIPanGestureRecognizer手势当该图片捕获到用户的拖动手势时会调用回调函数handlePan
UIPanGestureRecognizer *pan = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(handlePan:)]; [self.imgView setUserInteractionEnabled:YES]; [self.imgView addGestureRecognizer:pan]; [pan release];handlePan函数代码如下:
- (void) handlePan: (UIPanGestureRecognizer *)rec{ NSLog(@"xxoo---xxoo---xxoo"); CGPoint point = [rec translationInView:self.view]; NSLog(@"%f,%f",point.x,point.y); rec.view.center = CGPointMake(rec.view.center.x + point.x, rec.view.center.y + point.y); [rec setTranslation:CGPointMake(0, 0) inView:self.view]; }
以下为本人自己的理解,有不到之处请看官务必指教12
- (CGPoint)translationInView:(UIView *)view方法的API解释如下:
The translation of the pan gesture in the coordinate system of the specified view.
Return Value
A point identifying the new location of a view in the coordinate system of its designated superview.
字面理解是:
在指定的视图坐标系统中转换(拖动?) pan gesture
返回参数:返回一个明确的新的坐标位置,在指定的父视图坐标系统中
简单的理解就是
该方法返回在横坐标上、纵坐标上拖动了多少像素
因为拖动起来一直是在递增,所以每次都要用setTranslation:方法制0这样才不至于不受控制般滑动出视图
- (CGPoint)velocityInView:(UIView *)view方法的API解释如下:
The velocity of the pan gesture in the coordinate system of the specified view.
Return Value
The velocity of the pan gesture, which is expressed in points per second. The velocity is broken into horizontal and vertical components.
字面理解:
在指定坐标系统中pan gesture拖动的速度
返回参数:返回这种速度
简单的理解就是
你拖动这个图片的时候肯定有个速度,因此返回值就是你拖动时X和Y轴上的速度,速度是矢量,有方向。
参考资料
http://www.cnblogs.com/andyque/archive/2011/12/30/2307060.html
- UIPanGestureRecognizer怎么用
- UIPanGestureRecognizer UISlider
- UITapGestureRecognizer与UIPanGestureRecognizer应用
- 通过UIPanGestureRecognizer移动View
- UIPanGestureRecognizer学习笔记
- UIPanGestureRecognizer学习笔记
- UIPanGestureRecognizer使用小结
- UIPanGestureRecognizer学习笔记
- UIPanGestureRecognizer使用小结
- UIPanGestureRecognizer学习笔记
- UIPanGestureRecognizer学习笔记
- UIPanGestureRecognizer学习笔记
- UIPanGestureRecognizer类中translationInView
- UIPanGestureRecognizer使用小结
- UIPanGestureRecognizer使用小结
- UIPanGestureRecognizer学习笔记
- IOS UIPanGestureRecognizer 移动图片
- UIPanGestureRecognizer和UISwipeGestureRecognizer冲突?
- 创建类模式总结-简单工厂、工厂、抽象工厂、建造、原型
- 面试时绝对不能说的13句话
- Android4.4 系统下实现自动关机的方法总结 .
- Extjs 面板控件panel应用
- 学习c语言的经验
- UIPanGestureRecognizer怎么用
- 标牌厂 解析癫痫病怎么引起的_潍坊癫痫挂号
- 标牌厂 提问:癫痫病是怎么引起的_潍坊癫痫挂号
- 位运算
- linux 文件乱码问题
- iOS开发之删除过期Provisioning Profiles方法
- 铝标牌 癫痫怎么引起的你知道吗_潍坊癫痫挂号
- 实例:如何使用 Netty 下载文件
- IAT hooking