1
This commit is contained in:
@@ -25,13 +25,12 @@ static __weak UIView *sContainerView = nil; // 缺省承载视图(
|
||||
if (NSThread.isMainThread) { blk(); } else { dispatch_async(dispatch_get_main_queue(), blk); }
|
||||
}
|
||||
|
||||
+ (MBProgressHUD *)ensureHUDWithMask:(KBHUDMaskType)mask tap:(BOOL)tap {
|
||||
// 先尝试使用外部指定的容器视图(扩展环境推荐)
|
||||
/// 解析当前 HUD 需要附着的宿主视图
|
||||
+ (UIView *)kb_resolvedHostView {
|
||||
UIView *hostView = sContainerView;
|
||||
#ifndef KB_APP_EXTENSION
|
||||
// App 内退回到 KeyWindow
|
||||
if (!hostView) {
|
||||
// KB_KeyWindow 在 App 目标的 PrefixHeader 中定义;在扩展内不依赖它
|
||||
UIWindow *win = nil;
|
||||
// 避免强依赖某个前缀:这里以运行时方式访问 UIApplication 以规避编译期的 App Extension 限制
|
||||
Class uiAppClass = NSClassFromString(@"UIApplication");
|
||||
@@ -51,7 +50,11 @@ static __weak UIView *sContainerView = nil; // 缺省承载视图(
|
||||
hostView = win;
|
||||
}
|
||||
#endif
|
||||
return hostView;
|
||||
}
|
||||
|
||||
+ (MBProgressHUD *)ensureHUDWithMask:(KBHUDMaskType)mask tap:(BOOL)tap {
|
||||
UIView *hostView = [self kb_resolvedHostView];
|
||||
if (!hostView) { return nil; }
|
||||
|
||||
MBProgressHUD *hud = sHUD;
|
||||
@@ -119,8 +122,27 @@ static __weak UIView *sContainerView = nil; // 缺省承载视图(
|
||||
|
||||
+ (void)_showText:(NSString *)text icon:(nullable UIImage *)icon {
|
||||
[self onMain:^{
|
||||
MBProgressHUD *hud = [self ensureHUDWithMask:sMaskType tap:sDefaultTapToDismiss];
|
||||
if (!hud) { return; }
|
||||
MBProgressHUD *loadingHUD = sHUD;
|
||||
if (loadingHUD) {
|
||||
[loadingHUD hideAnimated:YES];
|
||||
}
|
||||
sHUD = nil;
|
||||
|
||||
UIView *hostView = [self kb_resolvedHostView];
|
||||
if (!hostView) { return; }
|
||||
|
||||
MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:hostView animated:YES];
|
||||
hud.removeFromSuperViewOnHide = YES;
|
||||
hud.bezelView.style = MBProgressHUDBackgroundStyleSolidColor;
|
||||
hud.bezelView.layer.cornerRadius = 12.0;
|
||||
hud.bezelView.color = [UIColor colorWithWhite:0 alpha:0.8];
|
||||
hud.contentColor = UIColor.whiteColor;
|
||||
hud.margin = 16;
|
||||
hud.label.numberOfLines = 0;
|
||||
hud.detailsLabel.numberOfLines = 0;
|
||||
[self applyMaskType:sMaskType hud:hud];
|
||||
[self applyTapToDismiss:sDefaultTapToDismiss hud:hud];
|
||||
|
||||
hud.mode = icon ? MBProgressHUDModeCustomView : MBProgressHUDModeText;
|
||||
hud.label.text = text ?: @"";
|
||||
hud.detailsLabel.text = nil;
|
||||
|
||||
@@ -14,17 +14,17 @@
|
||||
// 卡片标题/正文
|
||||
@property (nonatomic, strong) UILabel *titleLabel;
|
||||
@property (nonatomic, strong) UILabel *descLabel;
|
||||
@property (nonatomic, strong) UIView *line1;
|
||||
@property (nonatomic, strong) UILabel *q1Label;
|
||||
@property (nonatomic, strong) UIView *line2;
|
||||
@property (nonatomic, strong) UILabel *q2Label;
|
||||
@property (nonatomic, strong) UIStackView *buttonStack;
|
||||
@property (nonatomic, strong) UIButton *q1Button;
|
||||
@property (nonatomic, strong) UIButton *q2Button;
|
||||
|
||||
@end
|
||||
|
||||
@implementation KBGuideTopCell
|
||||
|
||||
- (void)setupUI {
|
||||
self.contentView.backgroundColor = [UIColor colorWithWhite:0.96 alpha:1.0];
|
||||
self.backgroundColor = [UIColor clearColor];
|
||||
self.contentView.backgroundColor = [UIColor clearColor];
|
||||
|
||||
// 头像
|
||||
[self.contentView addSubview:self.avatarView];
|
||||
@@ -55,33 +55,23 @@
|
||||
make.left.right.equalTo(self.titleLabel);
|
||||
}];
|
||||
|
||||
// 分隔、两条示例问题
|
||||
[self.cardView addSubview:self.line1];
|
||||
[self.cardView addSubview:self.q1Label];
|
||||
[self.cardView addSubview:self.line2];
|
||||
[self.cardView addSubview:self.q2Label];
|
||||
|
||||
[self.line1 mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.top.equalTo(self.descLabel.mas_bottom).offset(10);
|
||||
make.left.right.equalTo(self.cardView);
|
||||
make.height.mas_equalTo(KB_ONE_PIXEL);
|
||||
// 示例按钮区域
|
||||
[self.cardView addSubview:self.buttonStack];
|
||||
[self.buttonStack mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.top.equalTo(self.descLabel.mas_bottom).offset(20);
|
||||
make.left.equalTo(self.cardView).offset(12);
|
||||
make.right.equalTo(self.cardView).offset(-12);
|
||||
make.bottom.equalTo(self.cardView).offset(-16);
|
||||
}];
|
||||
|
||||
[self.q1Label mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.top.equalTo(self.line1.mas_bottom).offset(10);
|
||||
make.left.right.equalTo(self.titleLabel);
|
||||
}];
|
||||
[self.buttonStack addArrangedSubview:self.q1Button];
|
||||
[self.buttonStack addArrangedSubview:self.q2Button];
|
||||
|
||||
[self.line2 mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.top.equalTo(self.q1Label.mas_bottom).offset(10);
|
||||
make.left.right.equalTo(self.cardView);
|
||||
make.height.mas_equalTo(KB_ONE_PIXEL);
|
||||
[self.q1Button mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.height.mas_equalTo(46);
|
||||
}];
|
||||
|
||||
[self.q2Label mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.top.equalTo(self.line2.mas_bottom).offset(10);
|
||||
make.left.right.equalTo(self.titleLabel);
|
||||
make.bottom.equalTo(self.cardView).offset(-14);
|
||||
[self.q2Button mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.height.mas_equalTo(46);
|
||||
}];
|
||||
}
|
||||
|
||||
@@ -101,8 +91,12 @@
|
||||
if (!_cardView) {
|
||||
_cardView = [UIView new];
|
||||
_cardView.backgroundColor = [UIColor whiteColor];
|
||||
_cardView.layer.cornerRadius = 18;
|
||||
_cardView.layer.masksToBounds = YES;
|
||||
_cardView.layer.cornerRadius = 20;
|
||||
_cardView.layer.masksToBounds = NO;
|
||||
_cardView.layer.shadowColor = [UIColor colorWithRed:0.42 green:0.54 blue:0.83 alpha:0.35].CGColor;
|
||||
_cardView.layer.shadowOpacity = 0.5;
|
||||
_cardView.layer.shadowOffset = CGSizeMake(0, 6);
|
||||
_cardView.layer.shadowRadius = 14;
|
||||
}
|
||||
return _cardView;
|
||||
}
|
||||
@@ -111,9 +105,9 @@
|
||||
if (!_titleLabel) {
|
||||
_titleLabel = [UILabel new];
|
||||
_titleLabel.numberOfLines = 0;
|
||||
_titleLabel.font = [UIFont systemFontOfSize:16 weight:UIFontWeightSemibold];
|
||||
_titleLabel.textColor = [UIColor colorWithWhite:0.2 alpha:1.0];
|
||||
_titleLabel.text = KBLocalized(@"👋 Welcome to Key of Love Keyboard");
|
||||
_titleLabel.font = [KBFont regular:10];
|
||||
_titleLabel.textColor = [UIColor colorWithHex:0x929292];
|
||||
_titleLabel.text = KBLocalized(@"Welcome To Use The [key Of Love] Keyboard");
|
||||
}
|
||||
return _titleLabel;
|
||||
}
|
||||
@@ -122,42 +116,60 @@
|
||||
if (!_descLabel) {
|
||||
_descLabel = [UILabel new];
|
||||
_descLabel.numberOfLines = 0;
|
||||
_descLabel.font = [UIFont systemFontOfSize:14];
|
||||
_descLabel.textColor = [UIColor colorWithWhite:0.2 alpha:1.0];
|
||||
_descLabel.text = KBLocalized(@"Tap any conversation to paste, then try any reply style~");
|
||||
_descLabel.font = [KBFont regular:10];
|
||||
_descLabel.textColor = [UIColor colorWithHex:0x929292];
|
||||
NSString *desc = KBLocalized(@"Click \"copy Any Conversation\", \"paste\"\nAnd Try Replying Using The Keyboard\n[persona] Method");
|
||||
NSMutableParagraphStyle *style = [[NSMutableParagraphStyle alloc] init];
|
||||
style.lineSpacing = 4;
|
||||
_descLabel.attributedText = [[NSAttributedString alloc] initWithString:desc attributes:@{
|
||||
NSParagraphStyleAttributeName : style
|
||||
}];
|
||||
}
|
||||
return _descLabel;
|
||||
}
|
||||
|
||||
- (UIView *)line1 { if (!_line1) { _line1 = [UIView new]; _line1.backgroundColor = [UIColor colorWithWhite:0.92 alpha:1.0]; } return _line1; }
|
||||
- (UIView *)line2 { if (!_line2) { _line2 = [UIView new]; _line2.backgroundColor = [UIColor colorWithWhite:0.92 alpha:1.0]; } return _line2; }
|
||||
|
||||
- (UILabel *)q1Label {
|
||||
if (!_q1Label) {
|
||||
_q1Label = [UILabel new];
|
||||
_q1Label.font = [UIFont systemFontOfSize:16 weight:UIFontWeightSemibold];
|
||||
_q1Label.textColor = [UIColor blackColor];
|
||||
_q1Label.text = KBLocalized(@"What are you doing?");
|
||||
// 支持点击复制
|
||||
_q1Label.userInteractionEnabled = YES;
|
||||
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(kb_onTapQ1)];
|
||||
[_q1Label addGestureRecognizer:tap];
|
||||
- (UIStackView *)buttonStack {
|
||||
if (!_buttonStack) {
|
||||
_buttonStack = [[UIStackView alloc] init];
|
||||
_buttonStack.axis = UILayoutConstraintAxisVertical;
|
||||
_buttonStack.distribution = UIStackViewDistributionFill;
|
||||
_buttonStack.spacing = 10;
|
||||
}
|
||||
return _q1Label;
|
||||
return _buttonStack;
|
||||
}
|
||||
|
||||
- (UILabel *)q2Label {
|
||||
if (!_q2Label) {
|
||||
_q2Label = [UILabel new];
|
||||
_q2Label.font = [UIFont systemFontOfSize:16 weight:UIFontWeightSemibold];
|
||||
_q2Label.textColor = [UIColor blackColor];
|
||||
_q2Label.text = KBLocalized(@"I'm going to take a shower.");
|
||||
// 支持点击复制
|
||||
_q2Label.userInteractionEnabled = YES;
|
||||
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(kb_onTapQ2)];
|
||||
[_q2Label addGestureRecognizer:tap];
|
||||
- (UIButton *)q1Button {
|
||||
if (!_q1Button) {
|
||||
_q1Button = [self kb_makeActionButton];
|
||||
[_q1Button setTitle:KBLocalized(@"I Miss You") forState:UIControlStateNormal];
|
||||
[_q1Button addTarget:self action:@selector(kb_onTapQ1) forControlEvents:UIControlEventTouchUpInside];
|
||||
}
|
||||
return _q2Label;
|
||||
return _q1Button;
|
||||
}
|
||||
|
||||
- (UIButton *)q2Button {
|
||||
if (!_q2Button) {
|
||||
_q2Button = [self kb_makeActionButton];
|
||||
[_q2Button setTitle:KBLocalized(@"I'm Going To Take A Bath") forState:UIControlStateNormal];
|
||||
[_q2Button addTarget:self action:@selector(kb_onTapQ2) forControlEvents:UIControlEventTouchUpInside];
|
||||
}
|
||||
return _q2Button;
|
||||
}
|
||||
|
||||
- (UIButton *)kb_makeActionButton {
|
||||
UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
|
||||
btn.backgroundColor = [UIColor whiteColor];
|
||||
btn.layer.cornerRadius = 4;
|
||||
btn.backgroundColor = [UIColor colorWithHex:0xF3F3F3];
|
||||
// btn.layer.borderWidth = 1;
|
||||
// btn.layer.borderColor = [UIColor colorWithRed:0.82 green:0.86 blue:0.99 alpha:1].CGColor;
|
||||
btn.titleLabel.font = [UIFont systemFontOfSize:16 weight:UIFontWeightSemibold];
|
||||
[btn setTitleColor:[UIColor colorWithHex:0x1B1F1A] forState:UIControlStateNormal];
|
||||
btn.titleLabel.numberOfLines = 0;
|
||||
btn.titleLabel.textAlignment = NSTextAlignmentCenter;
|
||||
btn.contentEdgeInsets = UIEdgeInsetsMake(10, 16, 10, 16);
|
||||
btn.adjustsImageWhenHighlighted = NO;
|
||||
return btn;
|
||||
}
|
||||
|
||||
/// 复制统一处理
|
||||
@@ -169,12 +181,12 @@
|
||||
|
||||
/// 点击第一条示例文案
|
||||
- (void)kb_onTapQ1 {
|
||||
[self kb_copyTextToPasteboard:self.q1Label.text];
|
||||
[self kb_copyTextToPasteboard:[self.q1Button titleForState:UIControlStateNormal]];
|
||||
}
|
||||
|
||||
/// 点击第二条示例文案
|
||||
- (void)kb_onTapQ2 {
|
||||
[self kb_copyTextToPasteboard:self.q2Label.text];
|
||||
[self kb_copyTextToPasteboard:[self.q2Button titleForState:UIControlStateNormal]];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@@ -38,6 +38,7 @@ typedef NS_ENUM(NSInteger, KBGuideItemType) {
|
||||
|
||||
/// 最近一次已知的键盘高度(用于初次展示蒙层时的 GIF 位置计算)
|
||||
@property (nonatomic, assign) CGFloat kb_currentKeyboardHeight;
|
||||
@property (nonatomic, strong) UIImageView *bgImageView; // 全屏背景图
|
||||
|
||||
@end
|
||||
|
||||
@@ -45,7 +46,15 @@ typedef NS_ENUM(NSInteger, KBGuideItemType) {
|
||||
|
||||
- (void)viewDidLoad {
|
||||
[super viewDidLoad];
|
||||
self.view.backgroundColor = [UIColor colorWithWhite:0.96 alpha:1.0];
|
||||
// self.view.backgroundColor = [UIColor colorWithWhite:0.96 alpha:1.0];
|
||||
self.view.backgroundColor = UIColor.clearColor;
|
||||
self.kb_navView.backgroundColor = [UIColor clearColor];
|
||||
self.bgImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"my_bg_icon"]];
|
||||
self.bgImageView.contentMode = UIViewContentModeScaleAspectFill;
|
||||
[self.view insertSubview:self.bgImageView belowSubview:self.kb_navView];
|
||||
[self.bgImageView mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.edges.equalTo(self.view);
|
||||
}];
|
||||
|
||||
[self.view addSubview:self.tableView];
|
||||
[self.view addSubview:self.inputBar];
|
||||
@@ -421,7 +430,7 @@ typedef NS_ENUM(NSInteger, KBGuideItemType) {
|
||||
_tableView.delegate = self;
|
||||
_tableView.dataSource = self;
|
||||
_tableView.separatorStyle = UITableViewCellSeparatorStyleNone; // 无分割线
|
||||
_tableView.backgroundColor = [UIColor colorWithWhite:0.96 alpha:1.0];
|
||||
_tableView.backgroundColor = [UIColor clearColor];
|
||||
_tableView.rowHeight = UITableViewAutomaticDimension;
|
||||
_tableView.estimatedRowHeight = 120; // 开启自适应高度
|
||||
_tableView.contentInset = UIEdgeInsetsMake(0, 0, 52 + KB_SafeAreaBottom(), 0);
|
||||
|
||||
Reference in New Issue
Block a user