diff --git a/keyBoard/Assets.xcassets/My/mask_top_title.imageset/Contents.json b/keyBoard/Assets.xcassets/My/mask_top_title.imageset/Contents.json new file mode 100644 index 0000000..236b5cb --- /dev/null +++ b/keyBoard/Assets.xcassets/My/mask_top_title.imageset/Contents.json @@ -0,0 +1,21 @@ +{ + "images" : [ + { + "filename" : "mask_top_title.png", + "idiom" : "universal", + "scale" : "1x" + }, + { + "idiom" : "universal", + "scale" : "2x" + }, + { + "idiom" : "universal", + "scale" : "3x" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/keyBoard/Assets.xcassets/My/mask_top_title.imageset/mask_top_title.png b/keyBoard/Assets.xcassets/My/mask_top_title.imageset/mask_top_title.png new file mode 100644 index 0000000..25100d4 Binary files /dev/null and b/keyBoard/Assets.xcassets/My/mask_top_title.imageset/mask_top_title.png differ diff --git a/keyBoard/Class/Guard/V/KBKeyboardMaskView.m b/keyBoard/Class/Guard/V/KBKeyboardMaskView.m index 0fd60d0..4ec1dc9 100644 --- a/keyBoard/Class/Guard/V/KBKeyboardMaskView.m +++ b/keyBoard/Class/Guard/V/KBKeyboardMaskView.m @@ -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 { diff --git a/keyBoard/Class/Guard/VC/KBGuideVC.m b/keyBoard/Class/Guard/VC/KBGuideVC.m index da458ce..fd21f98 100644 --- a/keyBoard/Class/Guard/VC/KBGuideVC.m +++ b/keyBoard/Class/Guard/VC/KBGuideVC.m @@ -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) { diff --git a/keyBoard/Class/Pay/V/KBVipReviewListCell.m b/keyBoard/Class/Pay/V/KBVipReviewListCell.m index 6acedaa..159de50 100644 --- a/keyBoard/Class/Pay/V/KBVipReviewListCell.m +++ b/keyBoard/Class/Pay/V/KBVipReviewListCell.m @@ -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; } diff --git a/keyBoard/Class/Pay/VC/KBVipPay.m b/keyBoard/Class/Pay/VC/KBVipPay.m index 8a3c2ad..efc4876 100644 --- a/keyBoard/Class/Pay/VC/KBVipPay.m +++ b/keyBoard/Class/Pay/VC/KBVipPay.m @@ -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]; diff --git a/keyBoard/Class/Shop/VC/KBShopItemVC.m b/keyBoard/Class/Shop/VC/KBShopItemVC.m index f75435d..b488d37 100644 --- a/keyBoard/Class/Shop/VC/KBShopItemVC.m +++ b/keyBoard/Class/Shop/VC/KBShopItemVC.m @@ -47,9 +47,7 @@ }]; } - if (@available(iOS 11.0, *)) { self.collectionView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever; - } [self beginFirstRefresh]; } diff --git a/keyBoard/KeyBoardPrefixHeader.pch b/keyBoard/KeyBoardPrefixHeader.pch index 55d3664..0dd7a9a 100644 --- a/keyBoard/KeyBoardPrefixHeader.pch +++ b/keyBoard/KeyBoardPrefixHeader.pch @@ -100,10 +100,8 @@ static inline UIWindow *KB_KeyWindow(void) { // Safe Area static inline UIEdgeInsets KB_SafeAreaInsets(void) { - if (@available(iOS 11.0, *)) { UIWindow *w = KB_KeyWindow(); return w ? w.safeAreaInsets : UIEdgeInsetsZero; - } return UIEdgeInsetsZero; }