iOS ???????????????????????????????????????????
???????????? ???????[ 2015/8/6 11:31:42 ] ??????????????? ???????
	????1??UIGestureRecognizer ????
	????????????? iOS ?з???????????????????????豸??????????
	????iOS ???? 3.2 ??????????Щ??????????UIGestureRecognizer ???????????????????????????????????????
	????UIPanGestureRecognizer???????
	????UIPinchGestureRecognizer??????
	????UIRotationGestureRecognizer???????
	????UITapGestureRecognizer??????
	????UILongPressGestureRecognizer????????
	????UISwipeGestureRecognizer???????
	?????????????????? UIGestureRecognizer ????????????????????????????
	????PS????????????????? #import <UIKit/UIGestureRecognizerSubclass.h>?????????????·?????
	????1 - (void)reset;
	????2
	????3 - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event;
	????4 - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event;
	????5 - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event;
	????6 - (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event;
	????7 //???????????? UIGestureRecognizer (UIGestureRecognizerProtected) ???????????????????????в?
	????UIGestureRecognizer ???й?????£?
	
	????2????????
	??????????????????У??????????????????????????? UITapGestureRecognizer??
	????????????????????????????????????????????????????????????????????????????????????
	???????仰????????????????????????????????????????????????ε??????????????????????????????????????????????????????????????ò??????????????????
	
	????????????????£?
	????1 typedef NS_ENUM(NSInteger?? UIGestureRecognizerState) {
	????2     UIGestureRecognizerStatePossible??   // ??δ???????????????????????????????????????????????
	????3     UIGestureRecognizerStateBegan??      // ???????????????????????????????????п???????仯???????????δ???
	????4     UIGestureRecognizerStateChanged??    // ?????????????
	????5     UIGestureRecognizerStateEnded??      // ????????????????????????????
	????6     UIGestureRecognizerStateCancelled??  // ????????????????????
	????7     UIGestureRecognizerStateFailed??     // ?????????????????????
	????8     UIGestureRecognizerStateRecognized = UIGestureRecognizerStateEnded // ????????????UIGestureRecognizerStateEnded
	????9 };
	????????????????? UITapGestureRecgnizer ???????????????????????????????1?????????????????????????β???????????????????????????????????ò???????????????3??????????
	????????????????????????Щ????????????????????????????????????κβ????????????????????????????????????????????????????????????????????????0?????????????????????????????????????????1??????????????????1?????????????????2???????????????????????????????????ò?????????????????д????????????2????????????????????3????????1?β????????
	????3?????????????
	????????????????????????
	???????????????????????????????????????????????????????????????????????л????????
	??????????????????????????????????????????
	??????????????? View ?С??????????????? View????????????? View ????????????????????????????????л????????
	????PS????????????????? View????????? View ?????ж???????????????????????Щ????????????????????????????????????Ч??????????????????????????????????? option ??????????????????????
	????4?????????
	??????????????
	?????????????????? UIImageView ???С?????????????????????????????????
	????????????????????????? KMGestureRecognizer???????????? UIView ?С?
	????????????е???????λ?????
	???????????е???????????
	????????????е?????????????
	????????????????????????????????????????????
	??????????????????????????????0.7
	?????????????????????????????????У??????????е???????????λ
	????????????????????????????????3?λ???????????????????????У??????????е???????????λ
	????Ч?????£?
	
	????KMGestureRecognizer.h
	????1 #import <UIKit/UIKit.h>
	????2
	????3 typedef NS_ENUM(NSUInteger?? Direction) {
	????4     DirectionUnknown??
	????5     DirectionLeft??
	????6     DirectionRight
	????7 };
	????8
	????9 @interface KMGestureRecognizer : UIGestureRecognizer
	????10 @property (assign?? nonatomic) NSUInteger tickleCount; //????????
	????11 @property (assign?? nonatomic) CGPoint currentTickleStart; //??????????????λ??
	????12 @property (assign?? nonatomic) Direction lastDirection; //?????????????
	????13
	????14 @end
	????KMGestureRecognizer.m
	????1 #import "KMGestureRecognizer.h"
	????2 #import <UIKit/UIGestureRecognizerSubclass.h>
	????3
	????4 @implementation KMGestureRecognizer
	????5 #define kMinTickleSpacing 20.0
	????6 #define kMaxTickleCount 3
	????7
	????8 - (void)reset {
	????9     _tickleCount = 0;
	????10     _currentTickleStart = CGPointZero;
	????11     _lastDirection = DirectionUnknown;
	????12    
	????13     if (self.state == UIGestureRecognizerStatePossible) {
	????14         self.state = UIGestureRecognizerStateFailed;
	????15     }
	????16 }
	????17
	????18 - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
	????19     UITouch *touch = [touches anyObject];
	????20     _currentTickleStart = [touch locationInView:self.view]; //?????????????????λ??
	????21 }
	????22
	????23 - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
	????24     //????????????????λ?á?????????????λ?á????? X ?????????????????????????
	????25     UITouch *touch = [touches anyObject];
	????26     CGPoint tickleEnd = [touch locationInView:self.view];
	????27     CGFloat tickleSpacing = tickleEnd.x - _currentTickleStart.x;
	????28     Direction currentDirection = tickleSpacing < 0 ? DirectionLeft : DirectionRight;
	????29    
	????30     //????? X ??????????????????
	????31     if (ABS(tickleSpacing) >= kMinTickleSpacing) {
	????32         //?ж?????????β????????????????????????????????л??????
	????33         if (_lastDirection == DirectionUnknown ||
	????34             (_lastDirection == DirectionLeft && currentDirection == DirectionRight) ||
	????35             (_lastDirection == DirectionRight && currentDirection == DirectionLeft)) {
	????36             _tickleCount++;
	????37             _currentTickleStart = tickleEnd;
	????38             _lastDirection = currentDirection;
	????39            
	????40             if (_tickleCount >= kMaxTickleCount && self.state == UIGestureRecognizerStatePossible) {
	????41                 self.state = UIGestureRecognizerStateEnded;
	????42                 //NSLog(@"?????????????????л??????");
	????43             }
	????44         }
	????45     }
	????46 }
	????47
	????48 - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
	????49     [self reset];
	????50 }
	????51
	????52 - (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event {
	????53     [self reset];
	????54 }
	????55
	????56 @end
	????ViewController.h
	????1 #import <UIKit/UIKit.h>
	????2 #import "KMGestureRecognizer.h"
	????3
	????4 @interface ViewController : UIViewController
	????5 @property (strong?? nonatomic) UIImageView *imgV;
	????6 @property (strong?? nonatomic) UIImageView *imgV2;
	????7 @property (strong?? nonatomic) KMGestureRecognizer *customGestureRecognizer;
	????8
	????9 @end
	????ViewController.m
	????1 #import "ViewController.h"
	????2
	????3 @interface ViewController ()
	????4 - (void)handlePan:(UIPanGestureRecognizer *)recognizer;
	????5 - (void)handlePinch:(UIPinchGestureRecognizer *)recognizer;
	????6 - (void)handleRotation:(UIRotationGestureRecognizer *)recognizer;
	????7 - (void)handleTap:(UITapGestureRecognizer *)recognizer;
	????8 - (void)handleLongPress:(UILongPressGestureRecognizer *)recognizer;
	????9 - (void)handleSwipe:(UISwipeGestureRecognizer *)recognizer;
	????10 - (void)handleCustomGestureRecognizer:(KMGestureRecognizer *)recognizer;
	????11
	????12 - (void)bindPan:(UIImageView *)imgVCustom;
	????13 - (void)bindPinch:(UIImageView *)imgVCustom;
	????14 - (void)bindRotation:(UIImageView *)imgVCustom;
	????15 - (void)bindTap:(UIImageView *)imgVCustom;
	????16 - (void)bindLongPress:(UIImageView *)imgVCustom;
	????17 - (void)bindSwipe;
	????18 - (void)bingCustomGestureRecognizer;
	????19 - (void)layoutUI;
	????20 @end
	????21
	????22 @implementation ViewController
	????23
	????24 - (void)viewDidLoad {
	????25     [super viewDidLoad];
	????26    
	????27     [self layoutUI];
	????28 }
	????29
	
??????
					
					???·???
App??С????H5?????????????????Щ??
2024/9/11 15:34:34?????????????????????????
2024/9/10 11:13:49P-One ???????????????????????????????????????
2024/9/10 10:14:12???????????????????????????
2024/9/9 18:04:26??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44
					
			
								
								
								
								
								
								
								
								
								
								
				
sales@spasvo.com