UIGestureRecognizer

Initializing a Gesture Recognizer

- (instancetype)initWithTarget:(id)target action:(SEL)action//创建一个UIGestureRecognizer,包含它的出发函数

 

Adding and Removing Targets and Actions

- (void)addTarget:(id)target action:(SEL)action//Adds a target and an action to a gesture-recognizer object.
- (void)removeTarget:(id)target action:(SEL)action//Removes a target and an action from a gesture-recognizer object.

 

Getting the Touches and Location of a Gesture

 

- (CGPoint)locationInView:(UIView *)view//相对于view的location。对 UISwipeGestureRecognizer and UITapGestureRecognizer有意义。
- (CGPoint)locationOfTouch:(NSUInteger)touchIndex inView:(UIView *)view//Returns the location of one of the gesture’s touches in the local coordinate system of a given view. - (NSUInteger)numberOfTouches//touches的个数

 

Getting the Recognizer’s State and View 

@property(nonatomic, readonly) UIGestureRecognizerState state//UIGestureRecognizerState
@property(nonatomic, readonly) UIView *view//The view the gesture recognizer is attached to. 被addGestureRecognizer:方法attach的
@property(nonatomic, getter=isEnabled) BOOL enabled//如果在手势正在辨认的时候改为NO,则转到cancelled state

 

Canceling and Delaying Touches

@property(nonatomic) BOOL cancelsTouchesInView
@property(nonatomic) BOOL delaysTouchesBegan
@property(nonatomic) BOOL delaysTouchesEnded

 

Specifying Dependencies Between Gesture Recognizers

- (void)requireGestureRecognizerToFail:(UIGestureRecognizer *)otherGestureRecognizer//Creates a dependency relationship between the receiver and another gesture recognizer.

This method creates a relationship with another gesture recognizer that delays the receiver’s transition out ofUIGestureRecognizerStatePossible. The state that the receiver transitions to depends on what happens withotherGestureRecognizer:

An example where this method might be called is when you want a single-tap gesture require that a double-tap gesture fail.

 

Setting and Getting the Delegate

@property(nonatomic, assign) id< UIGestureRecognizerDelegate > delegate

 

Methods For Subclasses

- (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
- (void)reset
- (void)ignoreTouch:(UITouch *)touch forEvent:(UIEvent *)event
- (BOOL)canBePreventedByGestureRecognizer:(UIGestureRecognizer*)preventingGestureRecognizer
- (BOOL)canPreventGestureRecognizer:(UIGestureRecognizer *)preventedGestureRecognizer
- (BOOL)shouldRequireFailureOfGestureRecognizer:(UIGestureRecognizer*)otherGestureRecognizer
- (BOOL)shouldBeRequiredToFailByGestureRecognizer:(UIGestureRecognizer*)otherGestureRecognizer

 

Constants

typedef enum {
   UIGestureRecognizerStatePossible,//默认状态。还未认出手势。
   
   UIGestureRecognizerStateBegan,//收到连续的手势。It sends its action message (or messages) at the next cycle of the run loop.
   UIGestureRecognizerStateChanged,//手势更改。It sends its action message (or messages) at the next cycle of the run loop.
   UIGestureRecognizerStateEnded,// It sends its action message (or messages) at the next cycle of the run loop and resets its state to UIGestureRecognizerStatePossible.
   UIGestureRecognizerStateCancelled, 
   UIGestureRecognizerStateFailed,//The gesture recognizer has received a multi-touch sequence that it cannot recognize as its gesture. No action message is sent and the gesture recognizer is reset to UIGestureRecognizerStatePossible. 
   UIGestureRecognizerStateRecognized//The gesture recognizer has received a multi-touch sequence that it recognizes as its gesture. 
} UIGestureRecognizerState; 

 

posted on 2014-09-22 16:05  嘉遁  阅读(276)  评论(0编辑  收藏  举报

导航