iOS之事件UIEvent

UIEvent之触摸事件

触摸事件定义: 凡事与用户触摸有关的操做 都是触摸事件

UIView继承自UIResponder(响应者类),所以用户能够处理相关操做,若是想让UIView处理触摸事件,必需要重写父类的如下方法:

1,触摸开始,当手指刚接触屏幕的时候触发web

  • -(void)touchesBegan:(NSSetspa

     *)touches withEvent:(UIEvent *)event对象

2,移动触摸点,当手指在屏幕上移动的时候触发继承

  • -(void)touchesMoved:(NSSet事件

     *)touches withEvent:(UIEvent *)eventit

3,取消触摸,电话打入的时候会触发此事件io

  • -(void)touchesCancelled:(NSSetevent

     *)touches withEvent:(UIEvent *)eventwebkit

4,结束触摸,当手指离开屏幕的时候触摸此事件方法

  • -(void)touchesEnded:(NSSet

     *)touches withEvent:(UIEvent *)event

UITouch

触摸点UITouch对象,能够认为是咱们的手指,当咱们手指点击屏幕的时候,每次点击都会生成一个UITouch对象。咱们能够经过touch的一些属性,好比 在屏幕上的位置 点击次数 或者按压力度等

UITouch *touch = [touches anyObjecys];//获取触摸点集合 CGPoint *currentPoint = [touch locationInView:self];//获取当前触摸点的坐标

CGPoint *prePoint = [touch previousLocationInView:self];//获取上一个触摸点的坐标

相关文章
相关标签/搜索