feat: HomeV2 手表数据区高度动态调整 & 绑定弹窗姓名工号布局优化

- XJHomeWatchDataView 新增 heightChangeBlock,无数据/未登录高度 104,有数据高度 200
- XJHomePageV2HeardView 初始高度改为 104,绑定回调动态更新约束带动画
- BindWatchPopView 姓名工号同行布局,工号固定右侧优先显示,姓名占满剩余空间
This commit is contained in:
NSArray
2026-03-19 16:50:19 +08:00
parent 6f9f903ca1
commit 2c2f307247
5 changed files with 289 additions and 206 deletions
@@ -15,6 +15,9 @@
@property (nonatomic,strong) UITextField *nameField; @property (nonatomic,strong) UITextField *nameField;
@property (nonatomic,strong) UITextField *numberField; @property (nonatomic,strong) UITextField *numberField;
@property (nonatomic,strong) UIButton *actionBtn; @property (nonatomic,strong) UIButton *actionBtn;
@property (nonatomic,strong) UIView *gestureView;
@end @end
@implementation BindWatchPopView @implementation BindWatchPopView
@@ -26,7 +29,6 @@
self.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.4]; self.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.4];
[self createUI]; [self createUI];
[self addGesture];
[self addKeyboardNotification]; [self addKeyboardNotification];
} }
@@ -37,6 +39,7 @@
- (void)createUI { - (void)createUI {
self.bottomView = [[UIView alloc] init]; self.bottomView = [[UIView alloc] init];
self.bottomView.backgroundColor = UIColor.whiteColor; self.bottomView.backgroundColor = UIColor.whiteColor;
self.bottomView.layer.cornerRadius = 16; self.bottomView.layer.cornerRadius = 16;
@@ -46,9 +49,23 @@
[self.bottomView mas_makeConstraints:^(MASConstraintMaker *make) { [self.bottomView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.right.bottom.offset(0); make.left.right.bottom.offset(0);
make.height.offset(342); make.height.offset(254 + SafetyAreaHeight);
}]; }];
// 添加透明的手势响应区域(覆盖黑色背景)
UIView *gestureView = [[UIView alloc] init];
gestureView.backgroundColor = [UIColor clearColor];
gestureView.userInteractionEnabled = YES;
self.gestureView =gestureView;
[self addSubview:gestureView];
[gestureView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.right.top.offset(0);
make.bottom.equalTo(self.bottomView.mas_top);
}];
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(close)];
[gestureView addGestureRecognizer:tap];
/// 拖动条 /// 拖动条
UIView *indicator = [[UIView alloc] init]; UIView *indicator = [[UIView alloc] init];
@@ -65,7 +82,7 @@
UILabel *titleLab = [[UILabel alloc] init]; UILabel *titleLab = [[UILabel alloc] init];
titleLab.text = @"健康监测"; titleLab.text = @"健康监测工具绑定";
titleLab.font = [UIFont boldSystemFontOfSize:16]; titleLab.font = [UIFont boldSystemFontOfSize:16];
titleLab.textAlignment = NSTextAlignmentCenter; titleLab.textAlignment = NSTextAlignmentCenter;
[self.bottomView addSubview:titleLab]; [self.bottomView addSubview:titleLab];
@@ -77,68 +94,117 @@
HQUserInfo * user = [HQCommonUtils keyedUnarchiverWithKey:LoginUserInfo]; HQUserInfo * user = [HQCommonUtils keyedUnarchiverWithKey:LoginUserInfo];
self.workNoField = [self createTextField]; UILabel * nameLabel = [[UILabel alloc] init];
[self.bottomView addSubview:self.workNoField]; nameLabel.textColor = UIColorHex(#808080);
nameLabel.font= [UIFont systemFontOfSize:15 weight:UIFontWeightRegular];
[self.workNoField mas_makeConstraints:^(MASConstraintMaker *make) { nameLabel.textAlignment = NSTextAlignmentLeft;
make.left.offset(82);
make.right.offset(-15);
make.height.offset(52);
make.top.equalTo(titleLab.mas_bottom).offset(20);
}];
UILabel *workLab = [self createLabel:@"工 号:"];
if (!ValidStr(user.workNo)) {
self.workNoField.text = [NSString stringWithFormat:@"%@",user.workNo];
}
[self.bottomView addSubview:workLab];
[workLab mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.offset(0);
make.right.equalTo(self.workNoField.mas_left);
make.centerY.equalTo(self.workNoField);
}];
self.nameField = [self createTextField];
[self.bottomView addSubview:self.nameField];
[self.nameField mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.right.height.equalTo(self.workNoField);
make.top.equalTo(self.workNoField.mas_bottom).offset(16);
}];
if (!ValidStr(user.realname)) { if (!ValidStr(user.realname)) {
self.nameField.text = [NSString stringWithFormat:@"%@",user.realname]; nameLabel.text = [NSString stringWithFormat:@"%@",user.realname];
} }
[self.bottomView addSubview:nameLabel];
UILabel *nameLab = [self createLabel:@"姓 名:"]; // workLabel 先布局,固定右侧,宽度自适应内容,不压缩
[self.bottomView addSubview:nameLab]; UILabel * workLabel = [[UILabel alloc] init];
workLabel.textColor = UIColorHex(#808080);
workLabel.font = [UIFont systemFontOfSize:15 weight:UIFontWeightRegular];
workLabel.textAlignment = NSTextAlignmentRight;
// 工号不压缩、不拉伸
[workLabel setContentCompressionResistancePriority:UILayoutPriorityRequired
forAxis:UILayoutConstraintAxisHorizontal];
[workLabel setContentHuggingPriority:UILayoutPriorityRequired
forAxis:UILayoutConstraintAxisHorizontal];
if (!ValidStr(user.workNo)) {
workLabel.text = [NSString stringWithFormat:@"%@", user.workNo];
}
[self.bottomView addSubview:workLabel];
[nameLab mas_makeConstraints:^(MASConstraintMaker *make) { [workLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.offset(0); make.right.mas_offset(-21);
make.right.equalTo(self.nameField.mas_left); make.top.mas_equalTo(titleLab.mas_bottom).offset(20);
make.centerY.equalTo(self.nameField);
}]; }];
// nameLabel 左侧固定,右侧距 workLabel 一个字符宽度,姓名优先占满剩余空间
[nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_offset(16);
make.top.mas_equalTo(titleLab.mas_bottom).offset(20);
// 右侧距 workLabel 一个字符间距(约 15pt
make.right.equalTo(workLabel.mas_left).offset(-15);
}];
// 姓名可压缩,优先级低于工号
[nameLabel setContentCompressionResistancePriority:UILayoutPriorityDefaultLow
forAxis:UILayoutConstraintAxisHorizontal];
[nameLabel setContentHuggingPriority:UILayoutPriorityDefaultLow
forAxis:UILayoutConstraintAxisHorizontal];
// self.workNoField = [self createTextField];
// self.workNoField.userInteractionEnabled = false;
// [self.bottomView addSubview:self.workNoField];
//
// [self.workNoField mas_makeConstraints:^(MASConstraintMaker *make) {
// make.left.offset(82);
// make.right.offset(-15);
// make.height.offset(52);
// make.top.equalTo(titleLab.mas_bottom).offset(20);
// }];
//
//
UILabel * watchSNLab = [[UILabel alloc] init];
watchSNLab.text = @"心脑血管监测工具SN编码:";
watchSNLab.font = MEDIUMFONT(15);
watchSNLab.textAlignment = NSTextAlignmentLeft;
[self.bottomView addSubview:watchSNLab];
[watchSNLab mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(nameLabel.mas_left);
make.right.mas_offset(-21);
make.top.mas_equalTo(nameLabel.mas_bottom).offset(15);
}];
//
//
// self.nameField = [self createTextField];
// self.nameField.enabled = false;
// [self.bottomView addSubview:self.nameField];
//
// [self.nameField mas_makeConstraints:^(MASConstraintMaker *make) {
// make.left.right.height.equalTo(self.workNoField);
// make.top.equalTo(self.workNoField.mas_bottom).offset(16);
// }];
// if (!ValidStr(user.realname)) {
// self.nameField.text = [NSString stringWithFormat:@"%@",user.realname];
// }
//
// UILabel *nameLab = [self createLabel:@"姓 名:"];
// [self.bottomView addSubview:nameLab];
//
// [nameLab mas_makeConstraints:^(MASConstraintMaker *make) {
// make.left.offset(0);
// make.right.equalTo(self.nameField.mas_left);
// make.centerY.equalTo(self.nameField);
// }];
//
//
self.numberField = [self createTextField]; self.numberField = [self createTextField];
self.numberField.backgroundColor = KWhiteColor; NSMutableAttributedString *attrString = [[NSMutableAttributedString alloc] initWithString:@"请输入SN编码" attributes:
@{NSForegroundColorAttributeName:UIColorHex(#B6B6B6),
NSFontAttributeName:[UIFont systemFontOfSize:16 weight:UIFontWeightMedium]}
];
self.numberField.attributedPlaceholder = attrString;
[self.bottomView addSubview:self.numberField]; [self.bottomView addSubview:self.numberField];
[self.numberField mas_makeConstraints:^(MASConstraintMaker *make) { [self.numberField mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.right.height.equalTo(self.workNoField); make.left.mas_offset(15);
make.top.equalTo(self.nameField.mas_bottom).offset(16); make.right.mas_offset(-15);
make.height.mas_offset(52);
make.top.equalTo(watchSNLab.mas_bottom).offset(12);
}]; }];
UIView * lineV = [[UIView alloc] init];
lineV.backgroundColor = UIColorHex(#EAECF1);
[self.bottomView addSubview:lineV];
UILabel *xulieLab = [self createLabel:@"序列号:"]; [lineV mas_makeConstraints:^(MASConstraintMaker *make) {
[self.bottomView addSubview:xulieLab]; make.left.right.mas_offset(0);
make.height.mas_offset(1);
[xulieLab mas_makeConstraints:^(MASConstraintMaker *make) { make.top.mas_equalTo(self.numberField.mas_bottom).offset(12);
make.left.offset(0);
make.right.equalTo(self.numberField.mas_left);
make.centerY.equalTo(self.numberField);
}]; }];
@@ -155,7 +221,7 @@
make.centerX.offset(0); make.centerX.offset(0);
make.width.offset(215); make.width.offset(215);
make.height.offset(44); make.height.offset(44);
make.top.equalTo(self.numberField.mas_bottom).offset(30); make.top.equalTo(self.numberField.mas_bottom).offset(23);
}]; }];
} }
@@ -166,13 +232,17 @@
[self.actionBtn setTitle:@"解绑" forState:UIControlStateNormal]; [self.actionBtn setTitle:@"解绑" forState:UIControlStateNormal];
self.numberField.text = self.serialNumber; self.numberField.text = self.serialNumber;
self.numberField.backgroundColor = UIColorHex(#F5F7FB);
self.numberField.enabled = NO; self.numberField.enabled = NO;
} else { } else {
[self.actionBtn setTitle:@"绑定" forState:UIControlStateNormal]; [self.actionBtn setTitle:@"绑定" forState:UIControlStateNormal];
self.numberField.text = @""; self.numberField.text = @"";
self.numberField.enabled = YES; self.numberField.enabled = YES;
self.numberField.backgroundColor = KWhiteColor;
} }
} }
@@ -214,14 +284,6 @@
return field; return field;
} }
#pragma mark - 点击背景关闭
- (void)addGesture {
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(close)];
tap.cancelsTouchesInView = YES;
[self addGestureRecognizer:tap];
}
- (void)close { - (void)close {
@@ -247,11 +309,15 @@
- (void)keyboardShow:(NSNotification *)noti { - (void)keyboardShow:(NSNotification *)noti {
CGRect rect = [noti.userInfo[UIKeyboardFrameEndUserInfoKey] CGRectValue]; CGRect rect = [noti.userInfo[UIKeyboardFrameEndUserInfoKey] CGRectValue];
CGFloat keyboardH = rect.size.height; CGFloat keyboardH = rect.size.height;
[UIView animateWithDuration:0.25 animations:^{ [UIView animateWithDuration:0.25 animations:^{
self.bottomView.transform = CGAffineTransformMakeTranslation(0, -keyboardH); self.bottomView.transform = CGAffineTransformMakeTranslation(0, -keyboardH);
// 同步缩小 gestureView,避免手势区域覆盖 bottomView 上的按钮
[self.gestureView mas_updateConstraints:^(MASConstraintMaker *make) {
make.bottom.equalTo(self.bottomView.mas_top).offset(-keyboardH);
}];
[self layoutIfNeeded];
}]; }];
} }
@@ -259,6 +325,11 @@
[UIView animateWithDuration:0.25 animations:^{ [UIView animateWithDuration:0.25 animations:^{
self.bottomView.transform = CGAffineTransformIdentity; self.bottomView.transform = CGAffineTransformIdentity;
// 恢复 gestureView 约束
[self.gestureView mas_updateConstraints:^(MASConstraintMaker *make) {
make.bottom.equalTo(self.bottomView.mas_top).offset(0);
}];
[self layoutIfNeeded];
}]; }];
} }
@@ -38,6 +38,8 @@ NS_ASSUME_NONNULL_BEGIN
@property (nonatomic, copy, nullable) void (^bindDeviceBlock)(NSString * watchNo); @property (nonatomic, copy, nullable) void (^bindDeviceBlock)(NSString * watchNo);
@property (nonatomic, strong) NSString * totalponits;
@end @end
NS_ASSUME_NONNULL_END NS_ASSUME_NONNULL_END
@@ -19,6 +19,8 @@
@property (nonatomic, strong) SDCycleScrollView *adTitleView; @property (nonatomic, strong) SDCycleScrollView *adTitleView;
@property (nonatomic, strong) UILabel *nameLabel; @property (nonatomic, strong) UILabel *nameLabel;
@property (nonatomic, strong) XJHomeWatchDataView *watchDataView; @property (nonatomic, strong) XJHomeWatchDataView *watchDataView;
@property (nonatomic, strong) UILabel * toolTitleLab;
@end @end
@@ -158,6 +160,7 @@
toolTitleLab.text = @"今日健康积分 0 | 累计积分 0"; toolTitleLab.text = @"今日健康积分 0 | 累计积分 0";
toolTitleLab.textColor = UIColorHex(#116F6B); toolTitleLab.textColor = UIColorHex(#116F6B);
toolTitleLab.font = [UIFont systemFontOfSize:12 weight:UIFontWeightRegular]; toolTitleLab.font = [UIFont systemFontOfSize:12 weight:UIFontWeightRegular];
self.toolTitleLab = toolTitleLab;
[toolsView addSubview:toolTitleLab]; [toolsView addSubview:toolTitleLab];
[toolTitleLab mas_makeConstraints:^(MASConstraintMaker *make) { [toolTitleLab mas_makeConstraints:^(MASConstraintMaker *make) {
@@ -303,7 +306,7 @@
//手表数据 //手表数据
self.watchDataView = [[XJHomeWatchDataView alloc] initWithFrame:CGRectZero]; self.watchDataView = [[XJHomeWatchDataView alloc] initWithFrame:CGRectZero];
self.watchDataView.tabTitles = @[@"心脑血管", @"癌症", @"慢呼", @"糖尿病", @"亚健康"]; // self.watchDataView.tabTitles = @[@"心脑血管", @"癌症", @"慢呼", @"糖尿病", @"亚健康"];
self.watchDataView.tabSelectBlock = ^(NSInteger index, NSString *title) { self.watchDataView.tabSelectBlock = ^(NSInteger index, NSString *title) {
DLog(@"选中 %ld - %@", index, title); DLog(@"选中 %ld - %@", index, title);
// 切换 collectionView 到对应 page // 切换 collectionView 到对应 page
@@ -336,10 +339,20 @@
[self.watchDataView mas_makeConstraints:^(MASConstraintMaker *make) { [self.watchDataView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_offset(12); make.left.mas_offset(12);
make.right.mas_offset(-12); make.right.mas_offset(-12);
make.height.mas_offset(250); make.height.mas_offset(104);
make.top.mas_equalTo(lastImageView.mas_bottom).offset(12); make.top.mas_equalTo(lastImageView.mas_bottom).offset(12);
}]; }];
// 高度变化回调:无数据/未登录 104,有数据 205
self.watchDataView.heightChangeBlock = ^(CGFloat height) {
[weakSelf.watchDataView mas_updateConstraints:^(MASConstraintMaker *make) {
make.height.mas_equalTo(height);
}];
[UIView animateWithDuration:0.25 animations:^{
[weakSelf layoutIfNeeded];
}];
};
SDCycleScrollView * questionSDCycles = [SDCycleScrollView cycleScrollViewWithFrame:CGRectZero delegate:self placeholderImage:[UIImage imageNamed:@"placeholder"]]; SDCycleScrollView * questionSDCycles = [SDCycleScrollView cycleScrollViewWithFrame:CGRectZero delegate:self placeholderImage:[UIImage imageNamed:@"placeholder"]];
questionSDCycles.backgroundColor = KClearColor; questionSDCycles.backgroundColor = KClearColor;
@@ -364,6 +377,14 @@
} }
-(void)setTotalponits:(NSString *)totalponits {
_totalponits = totalponits;
self.toolTitleLab.text = _totalponits;
}
- (void)setModel:(XJHomeWatchModel *)model { - (void)setModel:(XJHomeWatchModel *)model {
@@ -46,6 +46,9 @@ typedef void(^watchDataDetailBlick)();
@property (nonatomic, copy) void (^changeTimeClickBlock)(NSString *startDate); @property (nonatomic, copy) void (^changeTimeClickBlock)(NSString *startDate);
/// 高度变化回调:无数据/未登录时返回 104,有数据时返回 205
@property (nonatomic, copy, nullable) void (^heightChangeBlock)(CGFloat height);
@end @end
NS_ASSUME_NONNULL_END NS_ASSUME_NONNULL_END
@@ -23,7 +23,7 @@ static CGFloat const kButtonGap = 10.0; // 按钮间距
@property (nonatomic, strong) YYLabel *watchNumberLabel; // @property (nonatomic, strong) YYLabel *watchNumberLabel; //
@property (nonatomic, strong) UIScrollView *tabScrollView; //@property (nonatomic, strong) UIScrollView *tabScrollView;
@property (nonatomic, strong) UIView *tabContentView; @property (nonatomic, strong) UIView *tabContentView;
@property (nonatomic, strong) NSMutableArray<UIButton *> *tabButtons; @property (nonatomic, strong) NSMutableArray<UIButton *> *tabButtons;
@property (nonatomic, strong) UICollectionView *collectionView; @property (nonatomic, strong) UICollectionView *collectionView;
@@ -214,25 +214,25 @@ weekLabel;
// [self updateWeekLabelWithType]; // [self updateWeekLabelWithType];
// //
// ── Tab ScrollView ─────────────────────────────────── // ── Tab ScrollView ───────────────────────────────────
_tabScrollView = [[UIScrollView alloc] init]; // _tabScrollView = [[UIScrollView alloc] init];
_tabScrollView.showsHorizontalScrollIndicator = NO; // _tabScrollView.showsHorizontalScrollIndicator = NO;
_tabScrollView.showsVerticalScrollIndicator = NO; // _tabScrollView.showsVerticalScrollIndicator = NO;
[self addSubview:_tabScrollView]; // [self addSubview:_tabScrollView];
//
[_tabScrollView mas_makeConstraints:^(MASConstraintMaker *make) { // [_tabScrollView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(heaedImg.mas_bottom); // make.top.equalTo(heaedImg.mas_bottom);
make.left.right.equalTo(self); // make.left.right.equalTo(self);
make.height.mas_equalTo(kTabScrollH); // make.height.mas_equalTo(kTabScrollH);
}]; // }];
// scrollView 内的容器 viewMasonry 驱动 contentSize // scrollView 内的容器 viewMasonry 驱动 contentSize
_tabContentView = [[UIView alloc] init]; // _tabContentView = [[UIView alloc] init];
[_tabScrollView addSubview:_tabContentView]; // [_tabScrollView addSubview:_tabContentView];
//
[_tabContentView mas_makeConstraints:^(MASConstraintMaker *make) { // [_tabContentView mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.equalTo(_tabScrollView); // 四边贴 scrollView // make.edges.equalTo(_tabScrollView); // 四边贴 scrollView
make.height.equalTo(_tabScrollView); // 固定高度 = scrollView,只横向滚动 // make.height.equalTo(_tabScrollView); // 固定高度 = scrollView,只横向滚动
}]; // }];
// ── 底部 CollectionView ────────────────────────────── // ── 底部 CollectionView ──────────────────────────────
UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init]; UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
@@ -252,31 +252,10 @@ weekLabel;
[self addSubview:_collectionView]; [self addSubview:_collectionView];
[_collectionView mas_makeConstraints:^(MASConstraintMaker *make) { [_collectionView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(_tabScrollView.mas_bottom); make.top.equalTo(@40);
make.left.right.bottom.equalTo(self); make.left.right.bottom.equalTo(self);
}]; }];
// ── 紧急开发中占位(tab 非第一个时显示)────────────────
_devView = [[UIView alloc] init];
_devView.backgroundColor = KWhiteColor;
_devView.hidden = YES;
[self addSubview:_devView];
[_devView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(_tabScrollView.mas_bottom);
make.left.right.bottom.equalTo(self);
}];
UILabel *devLabel = [[UILabel alloc] init];
devLabel.text = @"紧急开发中";
devLabel.textColor = [UIColor colorWithRed:0.6 green:0.6 blue:0.6 alpha:1.0];
devLabel.font = [UIFont systemFontOfSize:15.0];
devLabel.textAlignment = NSTextAlignmentCenter;
[_devView addSubview:devLabel];
[devLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.center.equalTo(_devView);
}];
// ── 未登录占位 Label ───────────────────────────────────────── // ── 未登录占位 Label ─────────────────────────────────────────
_emptyLabel = [[UILabel alloc] init]; _emptyLabel = [[UILabel alloc] init];
@@ -298,34 +277,34 @@ weekLabel;
[self addSubview:_emptyView]; [self addSubview:_emptyView];
[_emptyView mas_makeConstraints:^(MASConstraintMaker *make) { [_emptyView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(_tabScrollView.mas_bottom); make.top.equalTo(@40);
make.left.right.bottom.equalTo(self); make.left.right.bottom.equalTo(self);
}]; }];
// 空状态图标,宽高 59,居中,距 Tab 切换 View 底部 16 // // 空状态图标,宽高 59,居中,距 Tab 切换 View 底部 16
UIImageView *emptyImageView = [[UIImageView alloc] init]; // UIImageView *emptyImageView = [[UIImageView alloc] init];
emptyImageView.image = [UIImage imageNamed:@"ic_watch_empty"]; // emptyImageView.image = [UIImage imageNamed:@"ic_watch_empty"];
emptyImageView.contentMode = UIViewContentModeScaleAspectFit; // emptyImageView.contentMode = UIViewContentModeScaleAspectFit;
[_emptyView addSubview:emptyImageView]; // [_emptyView addSubview:emptyImageView];
//
[emptyImageView mas_makeConstraints:^(MASConstraintMaker *make) { // [emptyImageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.mas_offset(16); // make.top.mas_offset(16);
make.centerX.equalTo(_emptyView); // make.centerX.equalTo(_emptyView);
make.width.height.mas_offset(59); // make.width.height.mas_offset(59);
}]; // }];
//
// 提示文字:~ 暂无数据 ~,字号 11 regular,颜色 #B6B6B6 // // 提示文字:~ 暂无数据 ~,字号 11 regular,颜色 #B6B6B6
UILabel *emptyHintLabel = [[UILabel alloc] init]; // UILabel *emptyHintLabel = [[UILabel alloc] init];
emptyHintLabel.text = @"~ 暂无数据 ~"; // emptyHintLabel.text = @"~ 暂无数据 ~";
emptyHintLabel.textAlignment = NSTextAlignmentCenter; // emptyHintLabel.textAlignment = NSTextAlignmentCenter;
emptyHintLabel.textColor = UIColorHex(#B6B6B6); // emptyHintLabel.textColor = UIColorHex(#B6B6B6);
emptyHintLabel.font = [UIFont systemFontOfSize:11]; // emptyHintLabel.font = [UIFont systemFontOfSize:11];
[_emptyView addSubview:emptyHintLabel]; // [_emptyView addSubview:emptyHintLabel];
//
[emptyHintLabel mas_makeConstraints:^(MASConstraintMaker *make) { // [emptyHintLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(emptyImageView.mas_bottom).offset(8); // make.top.equalTo(emptyImageView.mas_bottom).offset(8);
make.centerX.equalTo(_emptyView); // make.centerX.equalTo(_emptyView);
}]; // }];
// 去绑定按钮:宽 80 高 24medium 13,颜色 #21BEBD,圆角 12,白底边框 1 // 去绑定按钮:宽 80 高 24medium 13,颜色 #21BEBD,圆角 12,白底边框 1
UIButton *bindBtn = [UIButton buttonWithType:UIButtonTypeCustom]; UIButton *bindBtn = [UIButton buttonWithType:UIButtonTypeCustom];
@@ -341,9 +320,9 @@ weekLabel;
[_emptyView addSubview:bindBtn]; [_emptyView addSubview:bindBtn];
[bindBtn mas_makeConstraints:^(MASConstraintMaker *make) { [bindBtn mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(emptyHintLabel.mas_bottom).offset(8); make.top.mas_offset(20);
make.centerX.equalTo(_emptyView); make.centerX.equalTo(_emptyView);
make.width.mas_offset(80); make.width.mas_offset(82);
make.height.mas_offset(24); make.height.mas_offset(24);
}]; }];
@@ -352,7 +331,6 @@ weekLabel;
} else { } else {
// 未登录:显示"暂未登录"文字,emptyView 保持隐藏 // 未登录:显示"暂未登录"文字,emptyView 保持隐藏
_emptyLabel.hidden = NO; _emptyLabel.hidden = NO;
_tabScrollView.hidden = NO;
_collectionView.hidden = NO; _collectionView.hidden = NO;
} }
} }
@@ -391,10 +369,13 @@ weekLabel;
if (_watchModel.hasWatch == true) { if (_watchModel.hasWatch == true) {
//有手表 //有手表
self.watchNumberLabel.text = [NSString stringWithFormat:@"监测工具编码:%@",_watchModel.watchNo]; self.watchNumberLabel.text = [NSString stringWithFormat:@"监测工具编码:%@",_watchModel.watchNo];
self.watchNumberLabel.textColor = UIColorHex(#14BEBE);
}else }else
{ {
self.watchNumberLabel.text = @""; self.watchNumberLabel.text = @"监测工具编码:暂无信息";
self.watchNumberLabel.textColor = UIColorHex(#808080);
self.dataList = @[]; self.dataList = @[];
} }
@@ -473,67 +454,67 @@ weekLabel;
#pragma mark - Public: Select Tab #pragma mark - Public: Select Tab
- (void)selectTabAtIndex:(NSInteger)index { //- (void)selectTabAtIndex:(NSInteger)index {
if (index < 0 || index >= (NSInteger)_tabButtons.count) return; // if (index < 0 || index >= (NSInteger)_tabButtons.count) return;
if (![HQCommonUtils isLogin]) { // if (![HQCommonUtils isLogin]) {
KPostNotification(KNotificationLoginStateChange, @NO); // KPostNotification(KNotificationLoginStateChange, @NO);
return; // return;
} // }
//
// // 恢复旧 Tab 样式
// UIButton *oldBtn = _tabButtons[_selectedIndex];
// oldBtn.backgroundColor = UIColorHex(#F6F7FB);
// oldBtn.titleLabel.font = [UIFont systemFontOfSize:14 weight:UIFontWeightRegular];
// [oldBtn setTitleColor:UIColorHex(#808080) forState:UIControlStateNormal];
//
// // 设置新 Tab 样式
// _selectedIndex = index;
// UIButton *newBtn = _tabButtons[index];
// newBtn.backgroundColor = UIColorHex(#14BEBE);
// newBtn.titleLabel.font = BOLDSYSTEMFONT(14);
// [newBtn setTitleColor:KWhiteColor forState:UIControlStateNormal];
//
// [self p_scrollToButton:newBtn];
//
// // tab 0:显示 CollectionView 并恢复轮播;其他:显示"紧急开发中"并暂停轮播
// BOOL isFirst = (index == 0);
// _collectionView.hidden = !isFirst;
// _devView.hidden = isFirst;
//
// if (isFirst) {
// // 切换回第一个 Tab,重新根据数据状态显示 emptyView
// BOOL isEmpty = (_dataList.count == 0);
// _emptyView.hidden = !isEmpty;
// [self p_restartAutoScroll];
// } else {
// // 切换到其他 Tab,隐藏 emptyView
// _emptyView.hidden = YES;
// [self p_stopAutoScroll];
// }
//
// // 通知外部高度变化
// if (self.tabSelectBlock) {
// self.tabSelectBlock(index, _tabTitles[index]);
// }
//}
// 恢复旧 Tab 样式 ///// 若按钮中心超过可视区一半,则滚动将其居中
UIButton *oldBtn = _tabButtons[_selectedIndex]; //- (void)p_scrollToButton:(UIButton *)btn {
oldBtn.backgroundColor = UIColorHex(#F6F7FB); // // layoutIfNeeded 保证 frame 已计算
oldBtn.titleLabel.font = [UIFont systemFontOfSize:14 weight:UIFontWeightRegular]; // [_tabScrollView layoutIfNeeded];
[oldBtn setTitleColor:UIColorHex(#808080) forState:UIControlStateNormal]; //
// CGFloat scrollW = _tabScrollView.bounds.size.width;
// 设置新 Tab 样式 // CGFloat contentW = _tabScrollView.contentSize.width;
_selectedIndex = index; // CGFloat btnCenterX = CGRectGetMidX(btn.frame);
UIButton *newBtn = _tabButtons[index]; //
newBtn.backgroundColor = UIColorHex(#14BEBE); // CGFloat offsetX = 0;
newBtn.titleLabel.font = BOLDSYSTEMFONT(14); // if (btnCenterX > scrollW / 2.0) {
[newBtn setTitleColor:KWhiteColor forState:UIControlStateNormal]; // offsetX = btnCenterX - scrollW / 2.0;
// offsetX = MIN(offsetX, MAX(contentW - scrollW, 0));
[self p_scrollToButton:newBtn]; // }
//
// tab 0:显示 CollectionView 并恢复轮播;其他:显示"紧急开发中"并暂停轮播 // [_tabScrollView setContentOffset:CGPointMake(offsetX, 0) animated:YES];
BOOL isFirst = (index == 0); //}
_collectionView.hidden = !isFirst;
_devView.hidden = isFirst;
if (isFirst) {
// 切换回第一个 Tab,重新根据数据状态显示 emptyView
BOOL isEmpty = (_dataList.count == 0);
_emptyView.hidden = !isEmpty;
[self p_restartAutoScroll];
} else {
// 切换到其他 Tab,隐藏 emptyView
_emptyView.hidden = YES;
[self p_stopAutoScroll];
}
// 通知外部高度变化
if (self.tabSelectBlock) {
self.tabSelectBlock(index, _tabTitles[index]);
}
}
/// 若按钮中心超过可视区一半,则滚动将其居中
- (void)p_scrollToButton:(UIButton *)btn {
// layoutIfNeeded 保证 frame 已计算
[_tabScrollView layoutIfNeeded];
CGFloat scrollW = _tabScrollView.bounds.size.width;
CGFloat contentW = _tabScrollView.contentSize.width;
CGFloat btnCenterX = CGRectGetMidX(btn.frame);
CGFloat offsetX = 0;
if (btnCenterX > scrollW / 2.0) {
offsetX = btnCenterX - scrollW / 2.0;
offsetX = MIN(offsetX, MAX(contentW - scrollW, 0));
}
[_tabScrollView setContentOffset:CGPointMake(offsetX, 0) animated:YES];
}
#pragma mark - DataList Setter #pragma mark - DataList Setter
@@ -546,14 +527,12 @@ weekLabel;
_emptyLabel.hidden = NO; _emptyLabel.hidden = NO;
_emptyView.hidden = YES; _emptyView.hidden = YES;
_collectionView.hidden = YES; _collectionView.hidden = YES;
_tabScrollView.hidden = YES;
return; return;
} }
// 已登录:隐藏 emptyLabel,显示内容区 // 已登录:隐藏 emptyLabel,显示内容区
_emptyLabel.hidden = YES; _emptyLabel.hidden = YES;
_collectionView.hidden = NO; _collectionView.hidden = NO;
_tabScrollView.hidden = NO;
// 无设备数据:显示 emptyView(图标 + 提示 + 去绑定按钮) // 无设备数据:显示 emptyView(图标 + 提示 + 去绑定按钮)
BOOL isEmpty = (_dataList.count == 0); BOOL isEmpty = (_dataList.count == 0);
@@ -567,6 +546,13 @@ weekLabel;
} else { } else {
[self p_stopAutoScroll]; [self p_stopAutoScroll];
} }
// 通知外部更新高度:无数据/未登录 104,有数据 205
BOOL needSmall = (isEmpty || ![HQCommonUtils isLogin]);
CGFloat newHeight = needSmall ? 104.0 : 200.0;
if (self.heightChangeBlock) {
self.heightChangeBlock(newHeight);
}
} }
#pragma mark - UICollectionViewDataSource #pragma mark - UICollectionViewDataSource