IOS学习 UITouch基础学习

来源:互联网 发布:印刷图书排版软件 编辑:程序博客网 时间:2024/05/17 02:40

再UIView中,可以重些以下四个方法来来控制用户的触摸动作:

 

 

  1. - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event;
  2. - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event;
  3. - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event;
  4. - (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event;
其中前三个方法很好理解,分别为触摸开始,移动,结束. 最后一个方法通常由系统掉用,比如在系统内存不够时,如果你正在触摸,那么这个方法可能会被得到掉用.但是一般情况下也不需要对此方法做处理.

通过NSSet count 可以获知触摸的指头的个数. Set中每一个元素就是UITouch对象.从UITouch对象中可以获取很多有用的信息.

[touch phase] 就可以获知触摸的方式,它是一个枚举类型来的.

 

typedef enum {

    UITouchPhaseBegan,             // whenever a finger touches the surface.

    UITouchPhaseMoved,             // whenever a finger moves on the surface.

    UITouchPhaseStationary,        // whenever a finger is touching the surface but hasn't moved since the previous event.

    UITouchPhaseEnded,             // whenever a finger leaves the surface.

    UITouchPhaseCancelled,         // whenever a touch doesn't end but we need to stop tracking (e.g. putting device to face)

} UITouchPhase;

 

 

touch tapCount 可以获取这个触摸的点击次数.(类似双击鼠标,如果双击就是2次)

touch timestamp 获取触摸的时间戳,这样可以计算一些点击的频率等应用.

touch locationInView: 获取坐标系,在某个view中

touch previousLocationInView: 获取在某个view中的前一次坐标系

touch gestureRecognizers 这个3.2新增加的(iPad),用于判断手势用

0 0
原创粉丝点击