This commit is contained in:
2025-11-27 20:05:39 +08:00
parent 8f16250cbe
commit 3144315de5
8 changed files with 59 additions and 23 deletions

View File

@@ -10,10 +10,12 @@
@interface KBKeyboardMaskView ()
@property (nonatomic, strong) UIButton *backButton;
@property (nonatomic, strong) FLAnimatedImageView *gifView;
@property (nonatomic, strong) UIImageView *tipLabel; //
@property (nonatomic, assign) CGFloat keyboardHeight;
@end
@implementation KBKeyboardMaskView
static const CGFloat KGifViewH = (209);
- (instancetype)initWithFrame:(CGRect)frame {
self = [super initWithFrame:frame];
@@ -29,11 +31,8 @@
[_backButton mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self).offset(9);
if (@available(iOS 11.0, *)) {
make.top.equalTo(self.mas_safeAreaLayoutGuideTop).offset(4);
} else {
make.top.equalTo(self).offset(40);
}
make.width.height.mas_equalTo(40);
}];
@@ -41,17 +40,24 @@
_gifView = [FLAnimatedImageView new];
_gifView.contentMode = UIViewContentModeScaleAspectFit;
_gifView.clipsToBounds = YES;
_gifView.layer.cornerRadius = 30;
// _gifView.clipsToBounds = true;
_gifView.layer.masksToBounds = true;
[self addSubview:_gifView];
// ==300 layoutSubviews
CGFloat screenW = UIScreen.mainScreen.bounds.size.width;
[_gifView mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerX.equalTo(self);
make.width.mas_equalTo(KBFit(316));
make.height.mas_equalTo(KBFit(209));
make.height.mas_equalTo(KBFit(KGifViewH));
// layoutSubviews
}];
//
_tipLabel = [UIImageView new];
_tipLabel.image = [UIImage imageNamed:@"mask_top_title"];
_tipLabel.contentMode = UIViewContentModeScaleAspectFit;
[self addSubview:_tipLabel];
//
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(onTapMask:)];
[self addGestureRecognizer:tap];
@@ -76,7 +82,7 @@
// -
// - 20pt safe
CGFloat viewH = CGRectGetHeight(self.bounds);
CGFloat gifH = 300.0;
CGFloat gifH = KBFit(KGifViewH);
CGFloat topMargin = 80.0; //
CGFloat bottomMargin = 20.0;
@@ -91,9 +97,29 @@
if (y < topMargin) y = topMargin;
}
CGRect frame = self.gifView.frame;
frame.origin.y = y;
self.gifView.frame = frame;
CGRect gifFrame = self.gifView.frame;
gifFrame.origin.y = y;
self.gifView.frame = gifFrame;
// gifView 20pt
CGFloat labelMaxWidth = CGRectGetWidth(self.bounds) - 40.0; // 20
if (labelMaxWidth < 0) { labelMaxWidth = 0; }
UIImage *tipImage = self.tipLabel.image;
if (!tipImage) { return; }
CGFloat imgW = tipImage.size.width;
CGFloat imgH = tipImage.size.height;
if (imgW <= 0 || imgH <= 0) { return; }
CGFloat scale = 1.0;
if (imgW > labelMaxWidth && labelMaxWidth > 0) {
scale = labelMaxWidth / imgW;
}
CGFloat labelW = imgW * scale;
CGFloat labelH = imgH * scale;
CGFloat labelX = (CGRectGetWidth(self.bounds) - labelW) * 0.5;
CGFloat labelBottom = CGRectGetMinY(self.gifView.frame) - 20.0;
CGFloat labelY = labelBottom - labelH;
self.tipLabel.frame = CGRectMake(labelX, labelY, labelW, labelH);
}
- (void)onTapMask:(UITapGestureRecognizer *)gr {

View File

@@ -62,11 +62,8 @@ typedef NS_ENUM(NSInteger, KBGuideItemType) {
make.left.right.equalTo(self.view);
make.height.mas_equalTo(52);
//
if (@available(iOS 11.0, *)) {
self.inputBarBottom = make.bottom.equalTo(self.view.mas_safeAreaLayoutGuideBottom);
} else {
self.inputBarBottom = make.bottom.equalTo(self.view);
}
}];
[self.textField mas_makeConstraints:^(MASConstraintMaker *make) {