iOS各种手势
来源:互联网 发布:螺纹算法 编辑:程序博客网 时间:2024/06/04 18:56
UIGestureRecognizer是一个定义基本手势的抽象类,具体什么手势,在以下子类中包含:
1、拍击UITapGestureRecognizer (任意次数的拍击)
2、向里或向外捏UIPinchGestureRecognizer (用于缩放)
3、摇动或者拖拽UIPanGestureRecognizer (拖动)
4、擦碰UISwipeGestureRecognizer (以任意方向拖动,具体向哪个方向,需要自己手动设置。当需要多个手势方向时,需要创建多个swipeGestureRecongnizer对象)
5、旋转UIRotationGestureRecognizer (手指朝相反方向移动)
6、长按UILongPressGestureRecognizer (长按)
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];
- }
UIPanGestureRecognizer类中translationInView方法和velocityInView方法有区别
apple官网解释:
- (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.
- (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.
这个返回的velocity 是矢量的 ,有大小有方向(velocity英文意思 就是 矢量速度 的意思)- iOS 各种手势用法
- iOS各种手势
- iOS各种手势识别
- iOS 各种手势集合
- IOS-各种手势
- iOS中的各种手势
- iOS 各种手势
- ios各种手势,很有意思
- IOS各种手势的使用
- ios各种手势,很有意思
- 【iOS开发-手势】iOS中各种手势总结
- ios中上下左右滑动的各种手势
- iOS各种手势与UISlider的运用
- iOS中解决各种手势冲突问题
- ios关于各种手势,挺有意思的
- iOS手势
- ios 手势
- IOS手势
- 程序员面试不完全指南
- php缺少 msvcr110.dll 怎么办
- 微博开发引子
- 使用浏览器访问 Linux 终端的方法
- 庖丁分词的源码分析
- iOS各种手势
- sql语句
- 在线视频移动化迁徙加速,UGC待开发
- iPhone实现QQ等app中右拖动屏幕返回上一层视图切换的效果(继承UINavigationController)
- HDU 1087
- mahout数据承载之FileDataModel的一个小插曲
- 实用Oracle存储过程技巧
- struts2的对象工厂(ObjectFactory)简介
- iOS 控件加载图片不显示的原因--多么痛的领悟