KBFunctionView 长按删除不弹出立刻清空按钮
This commit is contained in:
@@ -38,6 +38,7 @@ typedef NS_ENUM(NSInteger, KBBackspaceChunkClass) {
|
||||
@property (nonatomic, weak) UIView *containerView;
|
||||
@property (nonatomic, weak) UIView *backspaceButton;
|
||||
@property (nonatomic, strong) UILongPressGestureRecognizer *longPress;
|
||||
@property (nonatomic, assign) BOOL showClearLabelEnabled;
|
||||
@property (nonatomic, assign) BOOL backspaceHoldActive;
|
||||
@property (nonatomic, assign) NSTimeInterval backspaceHoldStartTime;
|
||||
@property (nonatomic, assign) BOOL backspaceChunkModeActive;
|
||||
@@ -58,13 +59,14 @@ typedef NS_ENUM(NSInteger, KBBackspaceChunkClass) {
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)bindDeleteButton:(UIView *)button {
|
||||
- (void)bindDeleteButton:(UIView *)button showClearLabel:(BOOL)showClearLabel {
|
||||
if (self.backspaceButton == button) { return; }
|
||||
|
||||
if (self.longPress && self.backspaceButton) {
|
||||
[self.backspaceButton removeGestureRecognizer:self.longPress];
|
||||
}
|
||||
self.backspaceButton = button;
|
||||
self.showClearLabelEnabled = showClearLabel;
|
||||
self.backspaceHoldActive = NO;
|
||||
self.backspaceChunkModeActive = NO;
|
||||
self.backspaceClearHighlighted = NO;
|
||||
@@ -105,7 +107,9 @@ typedef NS_ENUM(NSInteger, KBBackspaceChunkClass) {
|
||||
self.backspaceChunkModeActive = NO;
|
||||
[self kb_setBackspaceClearHighlighted:NO];
|
||||
[self kb_hideBackspaceClearLabel];
|
||||
[self kb_showBackspaceClearLabelIfNeeded];
|
||||
if (self.showClearLabelEnabled) {
|
||||
[self kb_showBackspaceClearLabelIfNeeded];
|
||||
}
|
||||
[self kb_backspaceStepForToken:token];
|
||||
} break;
|
||||
case UIGestureRecognizerStateChanged: {
|
||||
@@ -137,7 +141,9 @@ typedef NS_ENUM(NSInteger, KBBackspaceChunkClass) {
|
||||
}
|
||||
if (!self.backspaceChunkModeActive && elapsed >= kKBBackspaceChunkStartDelay) {
|
||||
self.backspaceChunkModeActive = YES;
|
||||
[self kb_showBackspaceClearLabelIfNeeded];
|
||||
if (self.showClearLabelEnabled) {
|
||||
[self kb_showBackspaceClearLabelIfNeeded];
|
||||
}
|
||||
}
|
||||
for (NSInteger i = 0; i < deleteCount; i++) {
|
||||
[proxy deleteBackward];
|
||||
@@ -271,6 +277,7 @@ typedef NS_ENUM(NSInteger, KBBackspaceChunkClass) {
|
||||
|
||||
- (void)kb_handleBackspaceLongPressChanged:(UILongPressGestureRecognizer *)gr {
|
||||
if (!self.backspaceHoldActive) { return; }
|
||||
if (!self.showClearLabelEnabled) { return; }
|
||||
[self kb_showBackspaceClearLabelIfNeeded];
|
||||
UIView *hostView = [self kb_hostView];
|
||||
if (!hostView) { return; }
|
||||
@@ -282,16 +289,19 @@ typedef NS_ENUM(NSInteger, KBBackspaceChunkClass) {
|
||||
}
|
||||
|
||||
- (void)kb_handleBackspaceLongPressEnded:(UILongPressGestureRecognizer *)gr {
|
||||
BOOL shouldClear = self.backspaceClearHighlighted;
|
||||
if (!shouldClear) {
|
||||
UIView *hostView = [self kb_hostView];
|
||||
CGPoint point = CGPointZero;
|
||||
if (gr && hostView) {
|
||||
point = [gr locationInView:hostView];
|
||||
} else if (self.backspaceHasLastTouchPoint) {
|
||||
point = self.backspaceLastTouchPointInSelf;
|
||||
BOOL shouldClear = NO;
|
||||
if (self.showClearLabelEnabled) {
|
||||
shouldClear = self.backspaceClearHighlighted;
|
||||
if (!shouldClear) {
|
||||
UIView *hostView = [self kb_hostView];
|
||||
CGPoint point = CGPointZero;
|
||||
if (gr && hostView) {
|
||||
point = [gr locationInView:hostView];
|
||||
} else if (self.backspaceHasLastTouchPoint) {
|
||||
point = self.backspaceLastTouchPointInSelf;
|
||||
}
|
||||
shouldClear = [self kb_isPointInsideBackspaceClearLabel:point];
|
||||
}
|
||||
shouldClear = [self kb_isPointInsideBackspaceClearLabel:point];
|
||||
}
|
||||
self.backspaceHoldActive = NO;
|
||||
self.backspaceChunkModeActive = NO;
|
||||
|
||||
Reference in New Issue
Block a user