與其他用戶界面控件交互
UIControl子類會覆蓋parentView的gesture.例如當用戶點擊UIButton時,UIButton會接受觸摸事件,它的parentView不會接收到.這僅適用於手勢識別重疊的默認動作的控制,其中包括:
- 一根手指單擊動作:UIButton, UISwitch, UIStepper, UISegmentedControl, and UIPageControl.
- 一根手指擦碰動作:UISlider
- 一根手指拖動動作:UISwitch
包含多點觸摸的事件
在iOS中,touch是指一根手指在屏幕上滑動、移動.而手勢是指有一根或多根手指,它的類是UITouch對象.多點觸摸事件是UIEventTypeTouches

當發生觸摸時,會觸發下列方法:
- touchesBegan:withEvent :觸摸屏幕時發生
- touchesMoved:withEvent :手指在屏幕上移動時發生
- touchesEnded:withEvent :觸摸結束時發生,即手指離開屏幕時
- touchesCancelled:withEvent :觸摸被系統取消時發生,如有電話時,該觸摸會被取消

改變默認的事件傳遞順序
你可以通過改變UIGestureRecognizer子類的屬性來改變默認的事件傳遞
- @property(nonatomic) BOOL delaysTouchesBegan; // default is NO. causes all touch events to be delivered to the target view only after this gesture has failed recognition. set to YES to prevent views from processing any touches that may be recognized as part of this gesture
- @property(nonatomic) BOOL delaysTouchesEnded; // default is YES. causes touchesEnded events to be delivered to the target view only after this gesture has failed recognition. this ensures that a touch that is part of the gesture can be cancelled if the gesture is recognized
如果一個gesture recognizer檢測到了一個不屬於它的touch,它將手勢直接發送給它的view,此時會調用ignoreTouch:forEvent: 方法直接傳遞給view.
創建自定義gesture recognizer步驟
- 創建UIGestureRecognizer的子類
- #import <UIKit/UIGestureRecognizerSubclass.h>
- 在子類沖重載下列方法
1.- (void)reset; 2.- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event; 3.- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event; 4.- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event; 5.- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event;
