添加guard 蒙层

This commit is contained in:
2025-11-27 15:34:33 +08:00
parent 2435d760e8
commit 2760a070a3
8 changed files with 270 additions and 11 deletions

View File

@@ -11,6 +11,7 @@
#import "KBGuideUserCell.h"
#import "KBPermissionViewController.h"
#import "KBKeyboardPermissionManager.h"
#import "KBKeyboardMaskView.h"
typedef NS_ENUM(NSInteger, KBGuideItemType) {
KBGuideItemTypeTop = 0, //
@@ -32,6 +33,12 @@ typedef NS_ENUM(NSInteger, KBGuideItemType) {
///
@property (nonatomic, copy, nullable) NSString *kb_lastInputModeIdentifier;
/// + GIF
@property (nonatomic, strong, nullable) KBKeyboardMaskView *kbKeyboardMaskView;
/// GIF
@property (nonatomic, assign) CGFloat kb_currentKeyboardHeight;
@end
@implementation KBGuideVC
@@ -94,8 +101,7 @@ typedef NS_ENUM(NSInteger, KBGuideItemType) {
//
[self kb_preparePermissionOverlayIfNeeded];
}
- (void)dealloc {
@@ -194,6 +200,7 @@ typedef NS_ENUM(NSInteger, KBGuideItemType) {
CGRect endFrame = [info[UIKeyboardFrameEndUserInfoKey] CGRectValue];
CGFloat screenH = UIScreen.mainScreen.bounds.size.height;
CGFloat kbHeight = MAX(0, screenH - endFrame.origin.y);
self.kb_currentKeyboardHeight = kbHeight;
CGFloat safeBtm = 0;
if (@available(iOS 11.0, *)) { safeBtm = self.view.safeAreaInsets.bottom; }
@@ -212,6 +219,13 @@ typedef NS_ENUM(NSInteger, KBGuideItemType) {
//
[self kb_evaluateCurrentInputModeAndNotifyIfNeeded];
}];
// GIF
if (self.kbKeyboardMaskView) {
[self.kbKeyboardMaskView updateForKeyboardHeight:kbHeight
duration:duration
curve:curve];
}
}
- (void)scrollToBottomAnimated:(BOOL)animated {
@@ -272,7 +286,9 @@ typedef NS_ENUM(NSInteger, KBGuideItemType) {
self.kb_lastInputModeIdentifier = currId;
BOOL isMine = [currId rangeOfString:KB_KEYBOARD_EXTENSION_BUNDLE_ID].location != NSNotFound;
[KBHUD showInfo:(isMine ? KBLocalized(@"是自己的键盘") : KBLocalized(@"❎不是自己的键盘"))];
// /
[self kb_updateKeyboardMaskForIsMyKeyboard:isMine];
}
///
@@ -290,6 +306,76 @@ typedef NS_ENUM(NSInteger, KBGuideItemType) {
});
}
/// /
- (void)kb_updateKeyboardMaskForIsMyKeyboard:(BOOL)isMine {
//
if (self.permVC && self.permVC.view.hidden == NO) {
if (self.kbKeyboardMaskView) {
self.kbKeyboardMaskView.hidden = YES;
}
return;
}
BOOL shouldShow = !isMine;
if (shouldShow) {
//
if (!self.kbKeyboardMaskView) {
KBKeyboardMaskView *mask = [[KBKeyboardMaskView alloc] initWithFrame:self.view.bounds];
__weak typeof(self) weakSelf = self;
mask.tapHandler = ^{
__strong typeof(weakSelf) self = weakSelf;
if (!self) return;
// / textField
if ([self.textField isFirstResponder]) {
// ->
[self.view endEditing:YES];
} else {
// ->
[self.textField becomeFirstResponder];
}
};
// 退 KBGuideVC
[mask.backButton addTarget:self action:@selector(kb_onMaskBack) forControlEvents:UIControlEventTouchUpInside];
self.kbKeyboardMaskView = mask;
if (self.permVC && self.permVC.view.superview == self.view) {
//
[self.view insertSubview:mask belowSubview:self.permVC.view];
} else {
[self.view addSubview:mask];
}
[mask mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.equalTo(self.view);
}];
// GIF
[mask updateForKeyboardHeight:self.kb_currentKeyboardHeight
duration:0
curve:UIViewAnimationOptionCurveEaseInOut];
}
}
if (!self.kbKeyboardMaskView) return;
BOOL currentlyVisible = !self.kbKeyboardMaskView.hidden && self.kbKeyboardMaskView.alpha > 0.01;
if (shouldShow == currentlyVisible) return;
self.kbKeyboardMaskView.hidden = NO;
CGFloat targetAlpha = shouldShow ? 1.0 : 0.0;
[UIView animateWithDuration:0.25 animations:^{
self.kbKeyboardMaskView.alpha = targetAlpha;
} completion:^(BOOL finished) {
self.kbKeyboardMaskView.hidden = !shouldShow;
}];
}
/// KBGuideVC 退
- (void)kb_onMaskBack {
[self.navigationController popViewControllerAnimated:YES];
}
#pragma mark - UITableView
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {