mirror of
https://github.com/zhigang1992/CCHLinkTextView.git
synced 2026-04-22 19:32:43 +08:00
Configurable allowable movement. Also re-enabled shouldRecognizeSimultaneouslyWithGestureRecognizer:
This commit is contained in:
@@ -18,11 +18,15 @@ typedef enum {
|
||||
/**
|
||||
A discreet gesture recognizer that sends action messages for touch down
|
||||
(UIGestureRecognizerStateBegan), touch up for a tap (UIGestureRecognizerStateRecognized,
|
||||
isLongPress == NO), and touch up for a long press (UIGestureRecognizerStateRecognized, isLongPress == NO).
|
||||
CCHLinkGestureRecognizerResultTap), touch up for a long press (UIGestureRecognizerStateRecognized,
|
||||
CCHLinkGestureRecognizerResultLongPress), and touch up when gesture has failed (UIGestureRecognizerStateRecognized,
|
||||
CCHLinkGestureRecognizerResultFailed).
|
||||
*/
|
||||
@interface CCHLinkGestureRecognizer : UIGestureRecognizer
|
||||
|
||||
@property (nonatomic, assign) CFTimeInterval minimumPressDuration;
|
||||
@property (nonatomic, assign) CGFloat allowableMovement;
|
||||
|
||||
@property (nonatomic, assign) CCHLinkGestureRecognizerResult result;
|
||||
|
||||
@end
|
||||
|
||||
@@ -10,8 +10,6 @@
|
||||
|
||||
#import <UIKit/UIGestureRecognizerSubclass.h>
|
||||
|
||||
#define MAX_SQUARED_DISTANCE (10 * 10)
|
||||
|
||||
@interface CCHLinkGestureRecognizer ()
|
||||
|
||||
@property (nonatomic, assign) CGPoint initialPoint;
|
||||
@@ -43,7 +41,12 @@
|
||||
|
||||
- (void)setUp
|
||||
{
|
||||
// Same defaults as UILongPressGestureRecognizer
|
||||
self.minimumPressDuration = 0.5;
|
||||
self.allowableMovement = 10;
|
||||
|
||||
self.result = CCHLinkGestureRecognizerResultUnknown;
|
||||
self.initialPoint = CGPointZero;
|
||||
}
|
||||
|
||||
- (void)reset
|
||||
@@ -107,7 +110,7 @@
|
||||
CGFloat yDistance = (self.initialPoint.y - point.y);
|
||||
CGFloat squaredDistance = (xDistance * xDistance) + (yDistance * yDistance);
|
||||
|
||||
BOOL isClose = (squaredDistance <= MAX_SQUARED_DISTANCE);
|
||||
BOOL isClose = (squaredDistance <= (self.allowableMovement * self.allowableMovement));
|
||||
return isClose;
|
||||
}
|
||||
|
||||
|
||||
@@ -43,8 +43,9 @@
|
||||
{
|
||||
self.linkRanges = [NSMutableArray array];
|
||||
self.touchDownCharacterIndex = -1;
|
||||
|
||||
|
||||
CCHLinkGestureRecognizer *linkGestureRecognizer = [[CCHLinkGestureRecognizer alloc] initWithTarget:self action:@selector(linkAction:)];
|
||||
linkGestureRecognizer.delegate = self;
|
||||
[self addGestureRecognizer:linkGestureRecognizer];
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user