iOS手势学习UIGestureRecognizer & cocos2d 手势推荐
手势识别类型:
// 长按
// 慢速拖动 // 两指向內或向外拨动 // 旋转 // 快速滑动 // 点击手势协议:
@protocol UIGestureRecognizerDelegate@optional// called when a gesture recognizer attempts to transition out of UIGestureRecognizerStatePossible. returning NO causes it to transition to UIGestureRecognizerStateFailed- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer;// called when the recognition of one of gestureRecognizer or otherGestureRecognizer would be blocked by the other// return YES to allow both to recognize simultaneously. the default implementation returns NO (by default no two gestures can be recognized simultaneously)//// note: returning YES is guaranteed to allow simultaneous recognition. returning NO is not guaranteed to prevent simultaneous recognition, as the other gesture's delegate may return YES- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer;// called before touchesBegan:withEvent: is called on the gesture recognizer for a new touch. return NO to prevent the gesture recognizer from seeing this touch- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch;@end
手势优先级:
// create a relationship with another gesture recognizer that will prevent this gesture's actions from being called until otherGestureRecognizer transitions to UIGestureRecognizerStateFailed// if otherGestureRecognizer transitions to UIGestureRecognizerStateRecognized or UIGestureRecognizerStateBegan then this recognizer will instead transition to UIGestureRecognizerStateFailed// example usage: a single tap may require a double tap to fail- (void)requireGestureRecognizerToFail:(UIGestureRecognizer *)otherGestureRecognizer;
各种手势Demo:
cocos2d手势库推荐: