1
This commit is contained in:
@@ -9,7 +9,12 @@
|
||||
#import <TargetConditionals.h>
|
||||
|
||||
@interface KBPermissionViewController ()
|
||||
|
||||
@property (nonatomic, strong) UIButton *backButton; // 左上角返回
|
||||
@property (nonatomic, strong) UILabel *titleLabel; // 标题
|
||||
@property (nonatomic, strong) UILabel *tipsLabel; // 步骤提示
|
||||
@property (nonatomic, strong) UIView *cardView; // 中部卡片
|
||||
@property (nonatomic, strong) UIButton *openButton; // 去设置
|
||||
@property (nonatomic, strong) UILabel *helpLabel; // 底部帮助
|
||||
@end
|
||||
|
||||
@implementation KBPermissionViewController
|
||||
@@ -18,67 +23,66 @@
|
||||
[super viewDidLoad];
|
||||
self.view.backgroundColor = [UIColor colorWithWhite:0.96 alpha:1.0];
|
||||
|
||||
UIButton *close = [UIButton buttonWithType:UIButtonTypeSystem];
|
||||
[close setTitle:@"X" forState:UIControlStateNormal];
|
||||
close.titleLabel.font = [UIFont systemFontOfSize:20 weight:UIFontWeightSemibold];
|
||||
close.tintColor = [UIColor darkTextColor];
|
||||
close.frame = CGRectMake(self.view.bounds.size.width - 44, 44, 28, 28);
|
||||
close.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleBottomMargin;
|
||||
[close addTarget:self action:@selector(dismissSelf) forControlEvents:UIControlEventTouchUpInside];
|
||||
[self.view addSubview:close];
|
||||
// 懒加载控件 + 添加到视图
|
||||
[self.view addSubview:self.backButton];
|
||||
[self.view addSubview:self.titleLabel];
|
||||
[self.view addSubview:self.tipsLabel];
|
||||
[self.view addSubview:self.cardView];
|
||||
[self.view addSubview:self.openButton];
|
||||
[self.view addSubview:self.helpLabel];
|
||||
|
||||
UILabel *title = [[UILabel alloc] init];
|
||||
title.text = [[KBLocalizationManager shared] localizedStringForKey:@"perm_title_enable" table:nil value:@"启用输入法"];
|
||||
title.font = [UIFont systemFontOfSize:22 weight:UIFontWeightSemibold];
|
||||
title.textColor = [UIColor blackColor];
|
||||
title.textAlignment = NSTextAlignmentCenter;
|
||||
title.frame = CGRectMake(24, 100, self.view.bounds.size.width - 48, 28);
|
||||
title.autoresizingMask = UIViewAutoresizingFlexibleWidth;
|
||||
[self.view addSubview:title];
|
||||
// Masonry 约束
|
||||
[self.backButton mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.left.equalTo(self.view).offset(16);
|
||||
make.top.equalTo(self.view.mas_safeAreaLayoutGuideTop).offset(8);
|
||||
|
||||
make.width.mas_equalTo(60);
|
||||
make.height.mas_equalTo(32);
|
||||
}];
|
||||
|
||||
UILabel *tips = [[UILabel alloc] init];
|
||||
// 保留简体中文为默认值;正式多语言请在 Localizable.strings 中提供
|
||||
tips.text = [[KBLocalizationManager shared] localizedStringForKey:@"perm_steps" table:nil value:@"1 开启键盘 > 2 允许完全访问"];
|
||||
tips.font = [UIFont systemFontOfSize:14];
|
||||
tips.textColor = [UIColor darkGrayColor];
|
||||
tips.textAlignment = NSTextAlignmentCenter;
|
||||
tips.frame = CGRectMake(24, CGRectGetMaxY(title.frame) + 8, self.view.bounds.size.width - 48, 20);
|
||||
tips.autoresizingMask = UIViewAutoresizingFlexibleWidth;
|
||||
[self.view addSubview:tips];
|
||||
[self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.top.equalTo(self.view.mas_safeAreaLayoutGuideTop).offset(48);
|
||||
|
||||
make.left.equalTo(self.view).offset(24);
|
||||
make.right.equalTo(self.view).offset(-24);
|
||||
make.height.mas_equalTo(28);
|
||||
}];
|
||||
|
||||
UIView *card = [[UIView alloc] initWithFrame:CGRectMake(32, CGRectGetMaxY(tips.frame) + 28, self.view.bounds.size.width - 64, 260)];
|
||||
card.backgroundColor = [UIColor whiteColor];
|
||||
card.layer.cornerRadius = 16;
|
||||
card.layer.shadowColor = [UIColor colorWithWhite:0 alpha:0.1].CGColor;
|
||||
card.layer.shadowOpacity = 1;
|
||||
card.layer.shadowRadius = 12;
|
||||
[self.view addSubview:card];
|
||||
[self.tipsLabel mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.top.equalTo(self.titleLabel.mas_bottom).offset(8);
|
||||
make.left.equalTo(self.view).offset(24);
|
||||
make.right.equalTo(self.view).offset(-24);
|
||||
}];
|
||||
|
||||
UIButton *open = [UIButton buttonWithType:UIButtonTypeSystem];
|
||||
[open setTitle:[[KBLocalizationManager shared] localizedStringForKey:@"perm_open_settings" table:nil value:@"去设置中开启"] forState:UIControlStateNormal];
|
||||
open.titleLabel.font = [UIFont systemFontOfSize:17 weight:UIFontWeightSemibold];
|
||||
[open setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
|
||||
open.backgroundColor = [UIColor colorWithRed:0.22 green:0.49 blue:0.96 alpha:1.0];
|
||||
open.layer.cornerRadius = 8;
|
||||
CGFloat btnW = self.view.bounds.size.width - 64;
|
||||
open.frame = CGRectMake(32, CGRectGetMaxY(card.frame) + 32, btnW, 48);
|
||||
open.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleTopMargin;
|
||||
[open addTarget:self action:@selector(openSettings) forControlEvents:UIControlEventTouchUpInside];
|
||||
[self.view addSubview:open];
|
||||
[self.cardView mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.top.equalTo(self.tipsLabel.mas_bottom).offset(28);
|
||||
make.left.equalTo(self.view).offset(32);
|
||||
make.right.equalTo(self.view).offset(-32);
|
||||
make.height.mas_equalTo(260);
|
||||
}];
|
||||
|
||||
UILabel *help = [[UILabel alloc] init];
|
||||
help.text = [[KBLocalizationManager shared] localizedStringForKey:@"perm_help" table:nil value:@"没有找到键盘? 请前往 设置 > 通用 > 键盘 > 键盘 > 添加新键盘"];
|
||||
help.font = [UIFont systemFontOfSize:12];
|
||||
help.textColor = [UIColor grayColor];
|
||||
help.textAlignment = NSTextAlignmentCenter;
|
||||
help.numberOfLines = 2;
|
||||
help.frame = CGRectMake(24, CGRectGetMaxY(open.frame) + 12, self.view.bounds.size.width - 48, 36);
|
||||
help.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleTopMargin;
|
||||
[self.view addSubview:help];
|
||||
[self.openButton mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.top.equalTo(self.cardView.mas_bottom).offset(32);
|
||||
make.left.equalTo(self.view).offset(32);
|
||||
make.right.equalTo(self.view).offset(-32);
|
||||
make.height.mas_equalTo(48);
|
||||
}];
|
||||
|
||||
[self.helpLabel mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.top.equalTo(self.openButton.mas_bottom).offset(12);
|
||||
make.left.equalTo(self.view).offset(24);
|
||||
make.right.equalTo(self.view).offset(-24);
|
||||
}];
|
||||
}
|
||||
|
||||
- (void)dismissSelf {
|
||||
[self dismissViewControllerAnimated:YES completion:nil];
|
||||
#pragma mark - Actions
|
||||
|
||||
- (void)onBack {
|
||||
// 先关闭自身,再让调用方按需处理(例如同时退出引导页)
|
||||
void (^handler)(void) = self.onBack;
|
||||
[self dismissViewControllerAnimated:YES completion:^{
|
||||
if (handler) handler();
|
||||
}];
|
||||
}
|
||||
|
||||
- (void)openSettings {
|
||||
@@ -93,4 +97,76 @@
|
||||
}
|
||||
}
|
||||
|
||||
#pragma mark - Lazy Subviews
|
||||
|
||||
- (UIButton *)backButton {
|
||||
if (!_backButton) {
|
||||
_backButton = [UIButton buttonWithType:UIButtonTypeSystem];
|
||||
[_backButton setTitle:KBLocalized(@"common_back") forState:UIControlStateNormal];
|
||||
_backButton.titleLabel.font = [UIFont systemFontOfSize:16 weight:UIFontWeightMedium];
|
||||
[_backButton setTitleColor:[UIColor darkTextColor] forState:UIControlStateNormal];
|
||||
[_backButton addTarget:self action:@selector(onBack) forControlEvents:UIControlEventTouchUpInside];
|
||||
}
|
||||
return _backButton;
|
||||
}
|
||||
|
||||
- (UILabel *)titleLabel {
|
||||
if (!_titleLabel) {
|
||||
_titleLabel = [UILabel new];
|
||||
_titleLabel.text = KBLocalized(@"perm_title_enable");
|
||||
_titleLabel.font = [UIFont systemFontOfSize:22 weight:UIFontWeightSemibold];
|
||||
_titleLabel.textColor = [UIColor blackColor];
|
||||
_titleLabel.textAlignment = NSTextAlignmentCenter;
|
||||
}
|
||||
return _titleLabel;
|
||||
}
|
||||
|
||||
- (UILabel *)tipsLabel {
|
||||
if (!_tipsLabel) {
|
||||
_tipsLabel = [UILabel new];
|
||||
_tipsLabel.text = KBLocalized(@"perm_steps");
|
||||
_tipsLabel.font = [UIFont systemFontOfSize:14];
|
||||
_tipsLabel.textColor = [UIColor darkGrayColor];
|
||||
_tipsLabel.textAlignment = NSTextAlignmentCenter;
|
||||
}
|
||||
return _tipsLabel;
|
||||
}
|
||||
|
||||
- (UIView *)cardView {
|
||||
if (!_cardView) {
|
||||
_cardView = [UIView new];
|
||||
_cardView.backgroundColor = [UIColor whiteColor];
|
||||
_cardView.layer.cornerRadius = 16;
|
||||
_cardView.layer.shadowColor = [UIColor colorWithWhite:0 alpha:0.1].CGColor;
|
||||
_cardView.layer.shadowOpacity = 1;
|
||||
_cardView.layer.shadowRadius = 12;
|
||||
}
|
||||
return _cardView;
|
||||
}
|
||||
|
||||
- (UIButton *)openButton {
|
||||
if (!_openButton) {
|
||||
_openButton = [UIButton buttonWithType:UIButtonTypeSystem];
|
||||
[_openButton setTitle:KBLocalized(@"perm_open_settings") forState:UIControlStateNormal];
|
||||
_openButton.titleLabel.font = [UIFont systemFontOfSize:17 weight:UIFontWeightSemibold];
|
||||
[_openButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
|
||||
_openButton.backgroundColor = [UIColor colorWithRed:0.22 green:0.49 blue:0.96 alpha:1.0];
|
||||
_openButton.layer.cornerRadius = 8;
|
||||
[_openButton addTarget:self action:@selector(openSettings) forControlEvents:UIControlEventTouchUpInside];
|
||||
}
|
||||
return _openButton;
|
||||
}
|
||||
|
||||
- (UILabel *)helpLabel {
|
||||
if (!_helpLabel) {
|
||||
_helpLabel = [UILabel new];
|
||||
_helpLabel.text = KBLocalized(@"perm_help");
|
||||
_helpLabel.font = [UIFont systemFontOfSize:12];
|
||||
_helpLabel.textColor = [UIColor grayColor];
|
||||
_helpLabel.textAlignment = NSTextAlignmentCenter;
|
||||
_helpLabel.numberOfLines = 2;
|
||||
}
|
||||
return _helpLabel;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
Reference in New Issue
Block a user