UIPanGestureRecognizer类中translationInView方法和velocityInView方法有什么区别
来源:互联网 发布:淘宝特卖网童装 编辑:程序博客网 时间:2024/05/22 01:33
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轴上的速度,速度是矢量,有方向
- UIPanGestureRecognizer类中translationInView方法和velocityInView方法有什么区别
- UIPanGestureRecognizer类中translationInView:方法和velocityInView:方法
- UIPanGestureRecognizer中locationInView和translationInView的区别
- UIPanGestureRecognizer类中translationInView
- locationInView 和translationInView这个两个方法的区别
- Python的静态方法和类方法有什么区别
- JAVA中“==”和“equals”方法有什么区别
- java中“==”和equals方法有什么区别
- scala中方法和函数有什么区别
- HTTP中GET和POST方法有什么区别
- 事件和方法有什么区别?
- sendRedirect()和forward()方法有什么区别?
- Vector类中的get和elementAt方法有什么区别
- 抽象类和虚方法有什么区别
- 在JAVA中, 静态方法和一般方法有什么区别?
- 在Java中方法重写和方法重载有什么区别
- 表单中POST方法与GET方法有什么区别
- ThinkPHP中M方法与D方法有什么区别
- [Java 12 IO] IO 总结
- XML实体注入
- android获取应用32位签名
- 使用SVN+Eclipse做软件版本控制
- ObjectArx学习笔记-选择文件及ACHAR用法
- UIPanGestureRecognizer类中translationInView方法和velocityInView方法有什么区别
- 随机地从大小n的数组中选出m个整数
- unity3d 调用C#的dll文件
- 实现RTP协议的H.264视频传输系统
- unity3D游戏开发实战原创视频讲座系列11之相扑游戏开发并发布到Win\Wp8
- ReportStudio入门教程(三十五) - 提示表达式的语法
- StringBuffer的用法
- Kalman滤波计算过程(仅供自己看的,没时间写整体理解,只写简要过程)
- 第1次实验——NPC问题(回溯算法)