添加按钮文字预览提示
This commit is contained in:
@@ -8,6 +8,7 @@
|
||||
#import "KBKey.h"
|
||||
#import "KBResponderUtils.h" // 封装的响应链工具
|
||||
#import "KBSkinManager.h"
|
||||
#import "KBKeyPreviewView.h"
|
||||
|
||||
@interface KBKeyboardView ()
|
||||
@property (nonatomic, strong) UIView *row1;
|
||||
@@ -17,6 +18,7 @@
|
||||
@property (nonatomic, strong) NSArray<NSArray<KBKey *> *> *keysForRows;
|
||||
// 长按退格的一次次删除控制标记(不使用 NSTimer,仅用 GCD 递归调度)
|
||||
@property (nonatomic, assign) BOOL backspaceHoldActive;
|
||||
@property (nonatomic, strong) KBKeyPreviewView *previewView;
|
||||
@end
|
||||
|
||||
@implementation KBKeyboardView
|
||||
@@ -463,6 +465,53 @@
|
||||
}
|
||||
}
|
||||
|
||||
// 在字符键按下时,显示一个上方气泡预览(类似系统键盘)。
|
||||
- (void)showPreviewForButton:(KBKeyButton *)button {
|
||||
KBKey *key = button.key;
|
||||
if (key.type != KBKeyTypeCharacter) return;
|
||||
|
||||
if (!self.previewView) {
|
||||
self.previewView = [[KBKeyPreviewView alloc] initWithFrame:CGRectZero];
|
||||
self.previewView.hidden = YES;
|
||||
[self addSubview:self.previewView];
|
||||
}
|
||||
|
||||
[self.previewView configureWithKey:key icon:button.iconView.image];
|
||||
|
||||
// 计算预览视图位置:在按钮上方稍微偏上
|
||||
CGRect btnFrameInSelf = [button convertRect:button.bounds toView:self];
|
||||
CGFloat previewWidth = MAX(CGRectGetWidth(btnFrameInSelf) * 1.4, 42.0);
|
||||
CGFloat previewHeight = CGRectGetHeight(btnFrameInSelf) * 1.2;
|
||||
CGFloat centerX = CGRectGetMidX(btnFrameInSelf);
|
||||
CGFloat centerY = CGRectGetMinY(btnFrameInSelf) - previewHeight * 0.6;
|
||||
|
||||
self.previewView.frame = CGRectMake(0, 0, previewWidth, previewHeight);
|
||||
self.previewView.center = CGPointMake(centerX, centerY);
|
||||
self.previewView.alpha = 0.0;
|
||||
self.previewView.hidden = NO;
|
||||
|
||||
[UIView animateWithDuration:0.08
|
||||
delay:0
|
||||
options:UIViewAnimationOptionBeginFromCurrentState | UIViewAnimationOptionCurveEaseOut
|
||||
animations:^{
|
||||
self.previewView.alpha = 1.0;
|
||||
}
|
||||
completion:nil];
|
||||
}
|
||||
|
||||
- (void)hidePreview {
|
||||
if (!self.previewView || self.previewView.isHidden) return;
|
||||
[UIView animateWithDuration:0.06
|
||||
delay:0
|
||||
options:UIViewAnimationOptionBeginFromCurrentState | UIViewAnimationOptionCurveEaseIn
|
||||
animations:^{
|
||||
self.previewView.alpha = 0.0;
|
||||
}
|
||||
completion:^(BOOL finished) {
|
||||
self.previewView.hidden = YES;
|
||||
}];
|
||||
}
|
||||
|
||||
// 长按退格:按住时以小间隔逐个删除;松手停止。(不使用 NSTimer/DisplayLink)
|
||||
- (void)onBackspaceLongPress:(UILongPressGestureRecognizer *)gr {
|
||||
switch (gr.state) {
|
||||
|
||||
Reference in New Issue
Block a user