调整逻辑
This commit is contained in:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user