KBFunctionView 长按删除不弹出立刻清空按钮
This commit is contained in:
@@ -11,8 +11,8 @@ NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
- (instancetype)initWithContainerView:(UIView *)containerView;
|
||||
|
||||
/// 配置删除按钮(包含长按删除与“立刻清空”提示)
|
||||
- (void)bindDeleteButton:(nullable UIView *)button;
|
||||
/// 配置删除按钮(包含长按删除;可选是否显示“立刻清空”提示)
|
||||
- (void)bindDeleteButton:(nullable UIView *)button showClearLabel:(BOOL)showClearLabel;
|
||||
|
||||
/// 触发“立刻清空”逻辑(可用于功能面板的清空按钮)
|
||||
- (void)performClearAction;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -865,7 +865,7 @@ static void KBULDarwinCallback(CFNotificationCenterRef center, void *observer, C
|
||||
[_deleteButtonInternal setImage:[UIImage imageNamed:@"kb_del_icon"] forState:UIControlStateNormal];
|
||||
|
||||
[_deleteButtonInternal addTarget:self action:@selector(onTapDelete) forControlEvents:UIControlEventTouchUpInside];
|
||||
[self.backspaceHandler bindDeleteButton:_deleteButtonInternal];
|
||||
[self.backspaceHandler bindDeleteButton:_deleteButtonInternal showClearLabel:NO];
|
||||
}
|
||||
return _deleteButtonInternal;
|
||||
}
|
||||
|
||||
@@ -93,7 +93,7 @@ static const CGFloat kKBLettersRow2EdgeSpacerMultiplier = 0.5;
|
||||
#pragma mark - Public
|
||||
|
||||
- (void)reloadKeys {
|
||||
[self.backspaceHandler bindDeleteButton:nil];
|
||||
[self.backspaceHandler bindDeleteButton:nil showClearLabel:NO];
|
||||
// 移除旧按钮
|
||||
for (UIView *row in @[self.row1, self.row2, self.row3, self.row4]) {
|
||||
[row.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];
|
||||
@@ -370,7 +370,7 @@ edgeSpacerMultiplier:(CGFloat)edgeSpacerMultiplier {
|
||||
[row addSubview:btn];
|
||||
|
||||
if (key.type == KBKeyTypeBackspace) {
|
||||
[self.backspaceHandler bindDeleteButton:btn];
|
||||
[self.backspaceHandler bindDeleteButton:btn showClearLabel:YES];
|
||||
}
|
||||
|
||||
// Shift 按钮选中态随大小写状态变化
|
||||
|
||||
Reference in New Issue
Block a user