IOS手指触摸滑动
2016-04-12 10:42
309 查看
主要是捕捉3个事件,触摸开始touchesBegan,触摸移动touchesMoved,触摸结束touchesEnded。
//滑动开始事件 - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { // NSLog(@"开始了"); UITouch *touch = [touches anyObject]; CGPoint pointone = [touch locationInView:self.view];//获得初始的接触点 //以字符的形式输出触摸点 _startX = pointone.x; NSLog(@"触摸点的坐标:%f",_startX); } //滑动移动事件 - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { // NSLog(@"移动啦"); UITouch *touch = [touches anyObject]; //imgViewTop是滑动后最后接触的View CGPoint pointtwo = [touch locationInView:self.view]; //获得滑动后最后接触屏幕的点 NSLog(@"移动点的坐标:%f,%f",pointtwo.x,_startX); int position = (pointtwo.x-_startX); NSLog(@"position is %d",position); if(fabs(pointtwo.x-_startX)>100) { //判断两点间的距离 NSLog(@"移动了"); _bMove = YES; } } //滑动结束处理事件 -(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event { UITouch *touch = [touches anyObject]; CGPoint pointtwo = [touch locationInView:self.view]; //获得滑动后最后接触屏幕的点 if((fabs(pointtwo.x-_startX)>50)&&(_bMove)) { //判断点的位置关系 左滑动 if(pointtwo.x-_startX>0) { //左向右滑动业务处理 NSLog(@"左向右移动"); } //判断点的位置关系 右滑动 else { //右向左滑动业务处理 NSLog(@"右移动"); [self goToNext]; } } }
相关文章推荐
- IOS中 Block简介与用法
- iOS instruments trace 文件解析方案
- Ios 与 js 交互
- Block(块)介绍之五:系统框架中的Block
- 收集各种 iOS App 开发可以用到的代码示例
- Block(块)介绍之四:回调CallBack
- iOS 字符串中删除反斜杠“\”
- 初识 Git(1)
- iOS模拟器获取相册可以真机获取相册失败
- iOS多线程篇:NSThread
- iOS图片不规则剪切
- 访问Block之外定义的变量
- Block的简单使用
- iOS开发人员需要了解的苹果开发者账号与邓白氏编码
- iOS-点击推送消息跳转处理
- iOS转场动画
- iOS-PageControl
- GitHub上值得关注的iOS开源项目
- iOS 开发之照片框架详解之二 —— PhotoKit 详解(下)
- IOS中Json解析的四种方法,推荐使用原生解析,和jsonKit