调整逻辑

This commit is contained in:
2025-11-03 18:45:06 +08:00
parent 915b329805
commit edf88721da
10 changed files with 82 additions and 28 deletions

View 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
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 388 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 674 B

View File

@@ -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 {

View File

@@ -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

View File

@@ -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 {