Files
keyboard/keyBoard/VC/KBPermissionViewController.m

188 lines
6.6 KiB
Mathematica
Raw Permalink Normal View History

2025-10-27 20:07:37 +08:00
//
// KBPermissionViewController.m
// CustomKeyboard
//
// Created by Mac on 2025/10/27.
//
#import "KBPermissionViewController.h"
@interface KBPermissionViewController ()
2025-11-03 16:57:24 +08:00
@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; //
2025-10-27 20:07:37 +08:00
@end
@implementation KBPermissionViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor = [UIColor colorWithWhite:0.96 alpha:1.0];
2025-11-03 16:57:24 +08:00
// +
[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];
// 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);
}];
[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);
}];
[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);
}];
[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);
}];
[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);
}];
2025-10-27 20:07:37 +08:00
}
2025-11-03 16:57:24 +08:00
#pragma mark - Actions
- (void)onBack {
2025-11-03 18:45:06 +08:00
//
// 1) presentingViewController VC pop
// 2) pop dismiss
UIViewController *presenter = self.presentingViewController;
if (!presenter) {
if (self.backHandler) self.backHandler();
return;
}
UINavigationController *nav = nil;
if ([presenter isKindOfClass:UINavigationController.class]) {
nav = (UINavigationController *)presenter;
} else if (presenter.navigationController) {
nav = presenter.navigationController;
}
if (nav) {
[nav popViewControllerAnimated:NO];
[nav dismissViewControllerAnimated:YES completion:^{ if (self.backHandler) self.backHandler(); }];
} else {
[self dismissViewControllerAnimated:YES completion:^{ if (self.backHandler) self.backHandler(); }];
}
2025-10-27 20:07:37 +08:00
}
- (void)openSettings {
NSURL *url = [NSURL URLWithString:UIApplicationOpenSettingsURLString];
UIApplication *app = [UIApplication sharedApplication];
if ([app canOpenURL:url]) {
if (@available(iOS 10.0, *)) {
[app openURL:url options:@{} completionHandler:nil];
} else {
[app openURL:url];
}
}
}
2025-11-03 16:57:24 +08:00
#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;
}
2025-10-27 20:07:37 +08:00
@end