博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Touch基本
阅读量:7053 次
发布时间:2019-06-28

本文共 1491 字,大约阅读时间需要 4 分钟。

UIviewController可以放入touch事件

 

UITouch的状态:

//用户刚触摸屏幕时

UITouchPhaseBegin 

//表示有触摸在屏幕上移动

UITouchPhaseMoved

//表示触摸仍停留在屏幕表面,不过之前一个事件之后没移动过

UITouchPhaseStationary

//在触摸远离屏幕时被触发

UITouchPhaseEnded

//在IOS系统停止跟踪特定触摸时发生,例如有电话打来

UITouchPhaseCancelled

 

 

//touch开始

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event;

//touch移动

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event;

//touch结束

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event;

//touch改变后

- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event;

获取当前touch

UITouch *touch = [touches anyObject];

获取touch坐标

CGPoint currentPoint = [touch locationInView:self];

开启多点触控

self.multipleTouchEnabled = YES;

 

手势

//轻击

UITapGestureRecognizer  次数 numberOfTapsRequired 

//捏合

UIPinchGestureRecognizer

//扫动

UISwipeGestureRecognizer 滑动方向 direction

//长按

UILongPressGestureRecognizer  按住时间minimumPressDuration

//拖动

UIPanGestureRecognizer

 UIPanGestureRecognizer *pan = (UIPanGestureRecognizer *)touch;

    

    UIView * view = pan.view;

    if (pan.state == UIGestureRecognizerStateBegan || pan.state == UIGestureRecognizerStateChanged

    {

        [[selfsuperview] bringSubviewToFront:self];

        //获得每次与上次的点的移动距离

        CGPoint translation = [pan translationInView:view.superview];

        NSLog(@"x坐标%fy坐标%f",translation.x,translation.y);

        [view setCenter:CGPointMake(view.center.x+translation.x, view.center.y + translation.y)];

        [pan setTranslation:CGPointZero inView:view.superview];

UIPan

转载于:https://www.cnblogs.com/ldming/archive/2012/06/02/2531696.html

你可能感兴趣的文章
CSS3 渐变(Gradients)
查看>>
Windows7关机、重启、待机、休眠命令
查看>>
如何在Xcode8上安装插件
查看>>
JQuery对CheckBox的一些相关操作
查看>>
IIS应用程序池的作用
查看>>
Project configuration is not up-to-date with pom.xml
查看>>
查询批次上课时间
查看>>
Ext.data.Store 中 data 的克隆原理
查看>>
Linux文件内容去重
查看>>
设计模式 之 状态模式
查看>>
Java泛型(一)ArrayList和HashMap
查看>>
redis笔记 (番外篇)——从RDBMS到NoSQL的架构演化及CAP原理
查看>>
iOS中根据已有经纬度定位并显示在地图上
查看>>
Git同时使用多个 ssh key
查看>>
hdu 2501
查看>>
findbugs错误类型对照表
查看>>
Eclipse代码补全,修改 空格键 "=" 键不上屏
查看>>
01背包问题的java界面实现
查看>>
[leetcode] Permutations
查看>>
查看Android应用包名package和入口activity名称
查看>>