UIPanGestureRecognizer学习笔记
来源:互联网 发布:软件升级方案 编辑:程序博客网 时间:2024/05/17 23:45
转自:http://blog.csdn.net/huifeidexin_1/article/details/8282035
UIGestureRecognizer是一个定义基本手势的抽象类,具体什么手势,在以下子类中包含:
1、拍击UITapGestureRecognizer (任意次数的拍击)
2、向里或向外捏UIPinchGestureRecognizer (用于缩放)
3、摇动或者拖拽UIPanGestureRecognizer (拖动)
4、擦碰UISwipeGestureRecognizer (以任意方向)
5、旋转UIRotationGestureRecognizer (手指朝相反方向移动)
6、长按UILongPressGestureRecognizer (长按)
UIPanGestureRecognizer类中translationInView方法和velocityInView方法有什么区别
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学习笔记
- UIPanGestureRecognizer学习笔记
- UIPanGestureRecognizer学习笔记
- UIPanGestureRecognizer学习笔记
- UIPanGestureRecognizer学习笔记
- UIPanGestureRecognizer学习笔记
- UIPanGestureRecognizer学习笔记
- IOS学习之UIPanGestureRecognizer使用
- UIGestureRecognizer学习之——UIPanGestureRecognizer
- UIPanGestureRecognizer UISlider
- UITapGestureRecognizer与UIPanGestureRecognizer应用
- 通过UIPanGestureRecognizer移动View
- UIPanGestureRecognizer使用小结
- UIPanGestureRecognizer使用小结
- UIPanGestureRecognizer怎么用
- UIPanGestureRecognizer类中translationInView
- UIPanGestureRecognizer使用小结
- UIPanGestureRecognizer使用小结
- iOS网络编程
- Android中的so注入(inject)和挂钩(hook) - For both x86 and arm
- linux命令学习之ls
- How to send email via Django?
- The currently displayed page contains invalid values解决方案
- UIPanGestureRecognizer学习笔记
- ICG技术专栏---互联网双出口的选择
- 有相同数字?
- ecmall 时间推后8小时问题解决
- 清空回收站之后正确的恢复办法
- ScriptManager之EnablePageMethods属性
- 判断两个有序数组中是否有相同的数字
- Oracle笔记 五、创建表、约束、视图、索引、序列、同义词、表空间
- 查看数据库sql执行效率