调整逻辑

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

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