添加键盘功能viewUI改动

This commit is contained in:
2025-11-26 21:16:56 +08:00
parent 80e4db86e4
commit 2435d760e8
17 changed files with 229 additions and 167 deletions

View File

@@ -22,8 +22,9 @@
- (instancetype)initWithFrame:(CGRect)frame{
if (self = [super initWithFrame:frame]) {
self.backgroundColor = [UIColor clearColor];
_leftTitles = @[@"ABC"];
_rightTitles = @[@"Upgrade VIP"];
//
_leftTitles = @[];
_rightTitles = @[];
[self buildUI];
}
return self;
@@ -38,91 +39,60 @@
#pragma mark - UI
- (void)buildUI {
// 便
[self addSubview:self.leftContainer];
// +
[self addSubview:self.globeButtonInternal];
[self addSubview:self.leftContainer];
[self addSubview:self.rightContainer];
// VIP 使 upgrad_vip_icon 115x35
[self.rightContainer mas_makeConstraints:^(MASConstraintMaker *make) {
make.right.equalTo(self.mas_right).offset(-12);
make.right.equalTo(self.mas_right).offset(-6);
make.centerY.equalTo(self.mas_centerY);
make.height.mas_equalTo(36);
make.width.mas_equalTo(115);
make.height.mas_equalTo(35);
}];
//
UIButton *vipButton = [UIButton buttonWithType:UIButtonTypeCustom];
vipButton.tag = 200; // index = 0
UIImage *vipImage = [UIImage imageNamed:@"upgrad_vip_icon"];
[vipButton setImage:vipImage forState:UIControlStateNormal];
vipButton.imageView.contentMode = UIViewContentModeScaleAspectFit;
vipButton.adjustsImageWhenHighlighted = YES;
[vipButton addTarget:self action:@selector(onRightTap:) forControlEvents:UIControlEventTouchUpInside];
[self.rightContainer addSubview:vipButton];
[vipButton mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.equalTo(self.rightContainer);
}];
self.rightButtonsInternal = @[vipButton];
// kb_refreshGlobeVisibility
[self.globeButtonInternal mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.mas_left).offset(12);
make.centerY.equalTo(self.mas_centerY);
make.width.height.mas_equalTo(32);
}];
// App 使 App_icon 34x34 36x36
[self.leftContainer mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.globeButtonInternal.mas_right).offset(8);
make.right.equalTo(self.rightContainer.mas_left).offset(-12);
make.centerY.equalTo(self.mas_centerY);
make.width.mas_equalTo(36);
make.height.mas_equalTo(36);
make.left.equalTo(self.mas_left).offset(12); // kb_refreshGlobeVisibility
}];
// 4
NSMutableArray<UIButton *> *leftBtns = [NSMutableArray arrayWithCapacity:4];
UIView *prev = nil;
for (NSInteger i = 0; i < self.leftTitles.count; i++) {
UIButton *btn = [self buildButtonWithTitle:(i < self.leftTitles.count ? self.leftTitles[i] : [NSString stringWithFormat:@"L%ld", (long)i])];
btn.tag = 100 + i;
[btn addTarget:self action:@selector(onLeftTap:) forControlEvents:UIControlEventTouchUpInside];
[self.leftContainer addSubview:btn];
[btn mas_makeConstraints:^(MASConstraintMaker *make) {
if (prev) {
make.left.equalTo(prev.mas_right).offset(8);
make.width.equalTo(prev);
} else {
make.left.equalTo(self.leftContainer.mas_left);
}
make.top.bottom.equalTo(self.leftContainer);
}];
prev = btn;
[leftBtns addObject:btn];
}
[prev mas_makeConstraints:^(MASConstraintMaker *make) {
make.right.equalTo(self.leftContainer.mas_right);
UIButton *appButton = [UIButton buttonWithType:UIButtonTypeCustom];
appButton.tag = 100; // index = 0
UIImage *appImage = [UIImage imageNamed:@"App_icon"];
[appButton setImage:appImage forState:UIControlStateNormal];
appButton.imageView.contentMode = UIViewContentModeScaleAspectFit;
appButton.adjustsImageWhenHighlighted = YES;
[appButton addTarget:self action:@selector(onLeftTap:) forControlEvents:UIControlEventTouchUpInside];
[self.leftContainer addSubview:appButton];
[appButton mas_makeConstraints:^(MASConstraintMaker *make) {
make.center.equalTo(self.leftContainer);
make.width.height.mas_equalTo(34); //
}];
self.leftButtonsInternal = leftBtns.copy;
// N
NSMutableArray<UIButton *> *rightBtns = [NSMutableArray arrayWithCapacity:3];
for (NSInteger i = 0; i < self.rightTitles.count; i++) {
UIButton *btn = [self buildButtonWithTitle:(i < self.rightTitles.count ? self.rightTitles[i] : [NSString stringWithFormat:@"R%ld", (long)i])];
btn.tag = 200 + i;
[self.rightContainer addSubview:btn];
[btn addTarget:self action:@selector(onRightTap:) forControlEvents:UIControlEventTouchUpInside];
[rightBtns addObject:btn];
}
// 1/2/3...
UIView *prevRight = nil; //
for (NSInteger i = rightBtns.count - 1; i >= 0; i--) {
UIButton *btn = rightBtns[i];
[btn mas_makeConstraints:^(MASConstraintMaker *make) {
if (!prevRight) {
//
make.right.equalTo(self.rightContainer.mas_right);
} else {
//
make.right.equalTo(prevRight.mas_left).offset(-8);
make.width.equalTo(prevRight);
}
make.top.bottom.equalTo(self.rightContainer);
}];
prevRight = btn;
}
//
if (prevRight) {
[prevRight mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.greaterThanOrEqualTo(self.rightContainer.mas_left);
}];
}
self.rightButtonsInternal = rightBtns.copy;
self.leftButtonsInternal = @[appButton];
//
[self kb_refreshGlobeVisibility];
@@ -144,17 +114,6 @@
}
}
- (UIButton *)buildButtonWithTitle:(NSString *)title {
UIButton *btn = [UIButton buttonWithType:UIButtonTypeSystem];
btn.layer.cornerRadius = 18;
btn.layer.masksToBounds = YES;
btn.backgroundColor = [UIColor colorWithWhite:1 alpha:0.9];
btn.titleLabel.font = [UIFont systemFontOfSize:14 weight:UIFontWeightMedium];
[btn setTitle:title forState:UIControlStateNormal];
[btn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
return btn;
}
#pragma mark - Lazy
- (UIView *)leftContainer {
@@ -201,8 +160,8 @@
} else {
make.left.equalTo(self.mas_left).offset(12);
}
make.right.equalTo(self.rightContainer.mas_left).offset(-12);
make.centerY.equalTo(self.mas_centerY);
make.width.mas_equalTo(36);
make.height.mas_equalTo(36);
}];