添加按钮文字预览提示
This commit is contained in:
@@ -8,7 +8,8 @@
|
||||
#import "KBSkinManager.h"
|
||||
|
||||
@interface KBKeyButton ()
|
||||
@property (nonatomic, strong) UIImageView *iconView;
|
||||
// 内部缓存:便于从按钮查找到所属的 KBKeyboardView
|
||||
@property (nonatomic, weak, readonly) UIView *kb_keyboardContainer;
|
||||
@end
|
||||
|
||||
@implementation KBKeyButton
|
||||
@@ -63,10 +64,8 @@
|
||||
|
||||
- (void)setHighlighted:(BOOL)highlighted {
|
||||
[super setHighlighted:highlighted];
|
||||
|
||||
// 按下时整体做一个等比缩放动画,不改背景色和透明度。
|
||||
// 这样无论是纯文字键还是整块皮肤图,都有统一的“按下”视觉反馈。
|
||||
NSLog(@"来了老弟=====");
|
||||
CGFloat scale = highlighted ? 0.9 : 1.0; // 可根据手感微调 0.9~0.95
|
||||
[UIView animateWithDuration:0.08
|
||||
delay:0
|
||||
@@ -75,6 +74,23 @@
|
||||
self.transform = CGAffineTransformMakeScale(scale, scale);
|
||||
}
|
||||
completion:nil];
|
||||
|
||||
// 将“按下/抬起”事件转发给键盘视图,用于显示/隐藏顶部预览气泡。
|
||||
UIView *container = self.kb_keyboardContainer;
|
||||
if ([container respondsToSelector:@selector(showPreviewForButton:)] &&
|
||||
[container respondsToSelector:@selector(hidePreview)]) {
|
||||
if (highlighted) {
|
||||
#pragma clang diagnostic push
|
||||
#pragma clang diagnostic ignored "-Warc-performSelector-leaks"
|
||||
[container performSelector:@selector(showPreviewForButton:) withObject:self];
|
||||
#pragma clang diagnostic pop
|
||||
} else {
|
||||
#pragma clang diagnostic push
|
||||
#pragma clang diagnostic ignored "-Warc-performSelector-leaks"
|
||||
[container performSelector:@selector(hidePreview)];
|
||||
#pragma clang diagnostic pop
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
- (void)setSelected:(BOOL)selected {
|
||||
@@ -124,3 +140,19 @@
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@implementation KBKeyButton (KBKeyboardContainer)
|
||||
|
||||
- (UIView *)kb_keyboardContainer {
|
||||
UIView *v = self.superview;
|
||||
while (v) {
|
||||
// KBKeyboardView 是当前容器类型,这里用类名字符串避免直接引用头文件死循环
|
||||
if ([NSStringFromClass(v.class) isEqualToString:@"KBKeyboardView"]) {
|
||||
return v;
|
||||
}
|
||||
v = v.superview;
|
||||
}
|
||||
return nil;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
Reference in New Issue
Block a user