1
This commit is contained in:
@@ -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 {
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -71,9 +71,7 @@ static NSString * const kKBVipReviewItemCellId = @"kKBVipReviewItemCellId";
|
||||
_collectionView.dataSource = self;
|
||||
_collectionView.delegate = self;
|
||||
[_collectionView registerClass:KBVipReviewItemCell.class forCellWithReuseIdentifier:kKBVipReviewItemCellId];
|
||||
if (@available(iOS 11.0, *)) {
|
||||
_collectionView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
|
||||
}
|
||||
}
|
||||
return _collectionView;
|
||||
}
|
||||
|
||||
@@ -242,9 +242,7 @@ static NSString * const kKBVipReviewListCellId = @"kKBVipReviewListCellId";
|
||||
_collectionView.dataSource = self;
|
||||
_collectionView.delegate = self;
|
||||
_collectionView.alwaysBounceVertical = YES;
|
||||
if (@available(iOS 11.0, *)) {
|
||||
_collectionView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
|
||||
}
|
||||
[_collectionView registerClass:KBVipPayHeaderView.class forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:kKBVipHeaderId];
|
||||
[_collectionView registerClass:KBVipSubscribeCell.class forCellWithReuseIdentifier:kKBVipSubscribeCellId];
|
||||
[_collectionView registerClass:KBVipReviewListCell.class forCellWithReuseIdentifier:kKBVipReviewListCellId];
|
||||
|
||||
@@ -47,9 +47,7 @@
|
||||
}];
|
||||
}
|
||||
|
||||
if (@available(iOS 11.0, *)) {
|
||||
self.collectionView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
|
||||
}
|
||||
|
||||
[self beginFirstRefresh];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user