调整逻辑
This commit is contained in:
22
keyBoard/Assets.xcassets/back_black_icon.imageset/Contents.json
vendored
Normal file
22
keyBoard/Assets.xcassets/back_black_icon.imageset/Contents.json
vendored
Normal file
@@ -0,0 +1,22 @@
|
||||
{
|
||||
"images" : [
|
||||
{
|
||||
"idiom" : "universal",
|
||||
"scale" : "1x"
|
||||
},
|
||||
{
|
||||
"filename" : "back@2x.png",
|
||||
"idiom" : "universal",
|
||||
"scale" : "2x"
|
||||
},
|
||||
{
|
||||
"filename" : "back@3x.png",
|
||||
"idiom" : "universal",
|
||||
"scale" : "3x"
|
||||
}
|
||||
],
|
||||
"info" : {
|
||||
"author" : "xcode",
|
||||
"version" : 1
|
||||
}
|
||||
}
|
||||
BIN
keyBoard/Assets.xcassets/back_black_icon.imageset/back@2x.png
vendored
Normal file
BIN
keyBoard/Assets.xcassets/back_black_icon.imageset/back@2x.png
vendored
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 388 B |
BIN
keyBoard/Assets.xcassets/back_black_icon.imageset/back@3x.png
vendored
Normal file
BIN
keyBoard/Assets.xcassets/back_black_icon.imageset/back@3x.png
vendored
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 674 B |
@@ -27,6 +27,8 @@ typedef NS_ENUM(NSInteger, KBGuideItemType) {
|
||||
@property (nonatomic, strong) UITapGestureRecognizer *bgTap;// 点击空白收起键盘
|
||||
|
||||
@property (nonatomic, strong) NSMutableArray<NSDictionary *> *items; // 数据源 [{type, text}]
|
||||
/// 权限引导页作为子控制器(用于“同时隐藏”)
|
||||
@property (nonatomic, strong, nullable) KBPermissionViewController *permVC;
|
||||
|
||||
@end
|
||||
|
||||
@@ -80,6 +82,9 @@ typedef NS_ENUM(NSInteger, KBGuideItemType) {
|
||||
|
||||
// 监听应用回到前台/变为活跃:用于从设置返回时再次校验权限
|
||||
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(kb_checkKeyboardPermission) name:UIApplicationDidBecomeActiveNotification object:nil];
|
||||
|
||||
// 提前创建并铺满权限引导页(默认隐藏),避免后续显示时出现布局进场感
|
||||
[self kb_preparePermissionOverlayIfNeeded];
|
||||
}
|
||||
|
||||
- (void)dealloc {
|
||||
@@ -101,23 +106,26 @@ typedef NS_ENUM(NSInteger, KBGuideItemType) {
|
||||
KBFARecord fa = [mgr lastKnownFullAccess];
|
||||
BOOL needGuide = (!enabled) || (enabled && fa == KBFARecordDenied);
|
||||
|
||||
UIViewController *top = [UIViewController kb_topMostViewController];
|
||||
if (needGuide) {
|
||||
if (![top isKindOfClass:[KBPermissionViewController class]]) {
|
||||
KBPermissionViewController *guide = [KBPermissionViewController new];
|
||||
guide.modalPresentationStyle = UIModalPresentationFullScreen;
|
||||
__weak typeof(self) weakSelf = self;
|
||||
guide.onBack = ^{
|
||||
// 用户主动点击“返回”时,同步退出引导页
|
||||
[weakSelf.navigationController popViewControllerAnimated:YES];
|
||||
};
|
||||
[top presentViewController:guide animated:YES completion:nil];
|
||||
}
|
||||
} else {
|
||||
if ([top isKindOfClass:[KBPermissionViewController class]]) {
|
||||
[top dismissViewControllerAnimated:YES completion:nil];
|
||||
}
|
||||
}
|
||||
[self kb_preparePermissionOverlayIfNeeded];
|
||||
BOOL show = needGuide;
|
||||
[UIView performWithoutAnimation:^{
|
||||
self.permVC.view.hidden = !show;
|
||||
}];
|
||||
}
|
||||
|
||||
/// 提前创建权限引导页覆盖层(仅一次)
|
||||
- (void)kb_preparePermissionOverlayIfNeeded {
|
||||
if (self.permVC) return;
|
||||
KBPermissionViewController *guide = [KBPermissionViewController new];
|
||||
guide.modalPresentationStyle = UIModalPresentationFullScreen; // 仅用于内部布局,不会真正 present
|
||||
KBWeakSelf;
|
||||
guide.backHandler = ^{ [weakSelf.navigationController popViewControllerAnimated:YES]; };
|
||||
self.permVC = guide;
|
||||
[self addChildViewController:guide];
|
||||
[self.view addSubview:guide.view];
|
||||
[guide.view mas_makeConstraints:^(MASConstraintMaker *make) { make.edges.equalTo(self.view); }];
|
||||
[guide didMoveToParentViewController:self];
|
||||
guide.view.hidden = YES; // 初始隐藏
|
||||
}
|
||||
|
||||
- (void)kb_didTapBackground {
|
||||
|
||||
@@ -12,7 +12,8 @@ NS_ASSUME_NONNULL_BEGIN
|
||||
@interface KBPermissionViewController : UIViewController
|
||||
|
||||
/// 点击页面左上角“返回”时回调。用于让调用方(如 KBGuideVC)一起退出等自定义行为。
|
||||
@property (nonatomic, copy, nullable) void (^onBack)(void);
|
||||
/// 注意:避免与按钮 action `onBack` 重名,故命名为 backHandler。
|
||||
@property (nonatomic, copy, nullable) void (^backHandler)(void);
|
||||
|
||||
@end
|
||||
|
||||
|
||||
@@ -78,11 +78,28 @@
|
||||
#pragma mark - Actions
|
||||
|
||||
- (void)onBack {
|
||||
// 先关闭自身,再让调用方按需处理(例如同时退出引导页)
|
||||
void (^handler)(void) = self.onBack;
|
||||
[self dismissViewControllerAnimated:YES completion:^{
|
||||
if (handler) handler();
|
||||
}];
|
||||
// 支持两种展示方式:
|
||||
// 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(); }];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)openSettings {
|
||||
|
||||
Reference in New Issue
Block a user