UITouch和UIGesturerecognize手勢

#UITouch
##事件的類型
- 觸摸事件
- 運動事件
- 遠程控制事件


##事件處理方法
`響應者類通過複寫以下方法,可以監聽觸摸事件`
   
```   
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event;
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event;
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event;
- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event;
```
##UITouch類中得常用屬性


- window     觸摸產生時所處的窗口
- view 觸摸產生的所處的視圖
- tapCount   短時間內輕擊屏幕的次數
- phase
- locationInView
- previousLocationInView

##事件傳遞


`點擊屏幕 -> ios捕獲觸摸將其打包成UIEvent對象 -> 事件隊列 ->UIApplication對象從事件隊列中取出最前面的事件並將其分發 -> 應用程序的主窗口 UIWindow -> 在由窗口對象發送事件給“第一響應者(觸摸的視圖)處理”
`
##響應者鏈的基本概念
***UIResponder是所有響應者對象的基類***   
`
第一響應者 -> 傳遞給父視圖 -> 其視圖控制器 -> UIWindow - UIApllacation
`
#UIGesturerecognize 手勢
##-輕拍   
***UITapGestureRecognizer***


- numberOfTapsRequired 輕拍幾下
- numberOfTouchRequired 需要幾個手指    
- [self.view addGestureRecognizer:tapGestureRecognizer]  添加手勢


##-縮放   
***UIPinchGestureRecognizer***


- scale 縮放比例
- velocity 速率
 
##-旋轉  
***UIRotationGestureRecognizer***


- rotation  旋轉
- velocity  速率


##-橫掃   
***UISwipeGestureRecognizer***  


- numberOfTouchesRequired 手指數
- direction  橫掃方向
- typedef enum {   
   UISwipeGestureRecognizerDirectionRight = 1 << 0,   
   UISwipeGestureRecognizerDirectionLeft  = 1 << 1,   
   UISwipeGestureRecognizerDirectionUp    = 1 << 2,   
   UISwipeGestureRecognizerDirectionDown  = 1 << 3   
}  UISwipeGestureRecognizerDirection;


##-拖動  
***UIPanGestureRecognizer***


- maximunNumberOfTouches 最多手指數
- minimunNumberOfTouches 最少手指數


##-點擊屏幕邊緣
   
***UIScreenEdgePanGestureRecognizer***


- edges

##-長按  
***UILongPressGestureRecognizer***


- minimunPressDuration 最小按壓時間
- numberOfTapsRequired 需要手指數
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章