Files
keyboard/CustomKeyboard/View/KBFullAccessGuideView.m

177 lines
7.4 KiB
Mathematica
Raw Normal View History

2025-10-30 20:46:54 +08:00
//
// KBFullAccessGuideView.m
// CustomKeyboard
2025-10-30 20:53:44 +08:00
// 访
2025-10-30 20:46:54 +08:00
#import "KBFullAccessGuideView.h"
#import "Masonry.h"
2025-11-04 16:37:24 +08:00
#import "KBResponderUtils.h" // UIInputViewController
#import "KBHUD.h"
#import "KBHostAppLauncher.h"
2025-10-30 20:46:54 +08:00
@interface KBFullAccessGuideView ()
@property (nonatomic, strong) UIControl *backdrop;
@property (nonatomic, strong) UIView *card;
//
@property (nonatomic, weak) UIInputViewController *ivc;
2025-10-30 20:46:54 +08:00
@end
@implementation KBFullAccessGuideView
+ (instancetype)build {
KBFullAccessGuideView *v = [[KBFullAccessGuideView alloc] initWithFrame:CGRectZero];
[v setupUI];
return v;
}
- (void)setupUI {
self.backgroundColor = [UIColor clearColor];
self.backdrop = [[UIControl alloc] init];
self.backdrop.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.35];
// [self.backdrop addTarget:self action:@selector(dismiss) forControlEvents:UIControlEventTouchUpInside];
[self addSubview:self.backdrop];
[self.backdrop mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.equalTo(self);
}];
self.card = [[UIView alloc] init];
self.card.backgroundColor = [UIColor whiteColor];
self.card.layer.cornerRadius = 16;
self.card.layer.masksToBounds = YES;
[self addSubview:self.card];
[self.card mas_makeConstraints:^(MASConstraintMaker *make) {
make.center.equalTo(self);
make.left.equalTo(self).offset(28);
make.right.equalTo(self).offset(-28);
}];
UILabel *title = [UILabel new];
2025-11-17 20:07:39 +08:00
title.text = KBLocalized(@"Turn on Allow Full Access to experience all features");
2025-10-30 20:46:54 +08:00
title.font = [UIFont boldSystemFontOfSize:16];
title.textColor = [UIColor blackColor];
title.textAlignment = NSTextAlignmentCenter;
[self.card addSubview:title];
[title mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.card).offset(16);
make.left.right.equalTo(self.card).insets(UIEdgeInsetsMake(0, 16, 0, 16));
}];
//
UIView *box = [UIView new];
box.backgroundColor = [UIColor colorWithWhite:0.98 alpha:1.0];
box.layer.cornerRadius = 12;
[self.card addSubview:box];
[box mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(title.mas_bottom).offset(12);
make.left.equalTo(self.card).offset(16);
make.right.equalTo(self.card).offset(-16);
make.height.mas_equalTo(100);
}];
2025-11-15 14:27:41 +08:00
UILabel *row1 = [UILabel new]; row1.text = AppName; row1.textColor = [UIColor blackColor];
2025-11-17 20:07:39 +08:00
UILabel *row2 = [UILabel new]; row2.text = KBLocalized(@"Allow Full Access"); row2.textColor = [UIColor blackColor];
2025-10-30 20:46:54 +08:00
[box addSubview:row1]; [box addSubview:row2];
[row1 mas_makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(box).offset(16); make.top.equalTo(box).offset(14); }];
UIView *line = [UIView new]; line.backgroundColor = [UIColor colorWithWhite:0.9 alpha:1.0];
[box addSubview:line];
[line mas_makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(box).offset(12); make.right.equalTo(box).offset(-12); make.centerY.equalTo(box); make.height.mas_equalTo(1); }];
[row2 mas_makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(box).offset(16); make.bottom.equalTo(box).offset(-14); }];
// 绿
UIView* (^switchView)(void) = ^UIView *{
UIView *sw = [UIView new];
sw.backgroundColor = [UIColor colorWithRed:0.12 green:0.75 blue:0.35 alpha:1.0];
sw.layer.cornerRadius = 15;
UIView *dot = [UIView new];
dot.backgroundColor = [UIColor whiteColor];
dot.layer.cornerRadius = 12;
[sw addSubview:dot];
[dot mas_makeConstraints:^(MASConstraintMaker *make) { make.centerY.equalTo(sw); make.right.equalTo(sw).offset(-3); make.width.height.mas_equalTo(24); }];
[sw mas_makeConstraints:^(MASConstraintMaker *make) { make.width.mas_equalTo(52); make.height.mas_equalTo(30); }];
return sw;
};
UIView *sw1 = switchView(); UIView *sw2 = switchView();
[box addSubview:sw1]; [box addSubview:sw2];
[sw1 mas_makeConstraints:^(MASConstraintMaker *make) { make.right.equalTo(box).offset(-12); make.centerY.equalTo(row1); }];
[sw2 mas_makeConstraints:^(MASConstraintMaker *make) { make.right.equalTo(box).offset(-12); make.centerY.equalTo(row2); }];
UIButton *go = [UIButton buttonWithType:UIButtonTypeSystem];
go.backgroundColor = [UIColor blackColor];
2025-11-17 20:07:39 +08:00
[go setTitle:KBLocalized(@"Go enable") forState:UIControlStateNormal];
2025-10-30 20:46:54 +08:00
[go setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
go.titleLabel.font = [UIFont boldSystemFontOfSize:18];
go.layer.cornerRadius = 12;
[go addTarget:self action:@selector(onTapGoEnable) forControlEvents:UIControlEventTouchUpInside];
[self.card addSubview:go];
[go mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(box.mas_bottom).offset(16);
make.left.equalTo(self.card).offset(16);
make.right.equalTo(self.card).offset(-16);
make.height.mas_equalTo(48);
make.bottom.equalTo(self.card).offset(-16);
}];
}
- (void)presentIn:(UIView *)parent {
if (!parent) return;
UIView *container = parent; // window
2025-10-30 20:46:54 +08:00
self.frame = container.bounds;
self.alpha = 0;
[container addSubview:self];
[self mas_makeConstraints:^(MASConstraintMaker *make) { make.edges.equalTo(container); }];
[UIView animateWithDuration:0.2 animations:^{ self.alpha = 1; }];
}
- (void)dismiss {
[UIView animateWithDuration:0.18 animations:^{ self.alpha = 0; } completion:^(BOOL finished) {
[self removeFromSuperview];
}];
}
+ (void)showInView:(UIView *)parent {
if (!parent) return;
// parent
for (UIView *v in parent.subviews) {
2025-10-30 20:46:54 +08:00
if ([v isKindOfClass:[KBFullAccessGuideView class]]) return;
}
KBFullAccessGuideView *view = [KBFullAccessGuideView build];
// ivc
view.ivc = KBFindInputViewController(parent);
[view presentIn:parent];
2025-10-30 20:46:54 +08:00
}
+ (void)dismissFromView:(UIView *)parent {
UIView *container = parent;
if (!container) return;
2025-10-30 20:46:54 +08:00
for (UIView *v in container.subviews) {
if ([v isKindOfClass:[KBFullAccessGuideView class]]) {
[(KBFullAccessGuideView *)v dismiss];
break;
}
}
}
#pragma mark - Actions
2025-11-04 16:37:24 +08:00
// KBResponderUtils.h
// App访宿 UIApplication + Scheme
2025-10-30 20:46:54 +08:00
- (void)onTapGoEnable {
2025-11-04 16:37:24 +08:00
UIInputViewController *ivc = KBFindInputViewController(self);
// responder
UIResponder *start = ivc.view ?: (UIResponder *)self;
// SchemeAppDelegate kbkeyboardAppExtension://settings
NSURL *scheme = [NSURL URLWithString:[NSString stringWithFormat:@"%@@//settings?src=kb_extension", KB_APP_SCHEME]];
BOOL ok = [KBHostAppLauncher openHostAppURL:scheme fromResponder:start];
if (ok) {
[self dismiss];
} else {
NSString *showInfo = [NSString stringWithFormat:KBLocalized(@"Follow: Settings → General → Keyboard → Keyboards → %@ → Allow Full Access"),AppName];
[KBHUD showInfo:showInfo];
}
2025-10-30 20:46:54 +08:00
}
@end