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];//獲取上一個觸摸點的座標

相關文章
相關標籤/搜索