手表解绑功能

This commit is contained in:
NSArray
2026-03-12 18:08:53 +08:00
parent a47d1a56fa
commit 1bfe617cab
16 changed files with 558 additions and 126 deletions
@@ -0,0 +1,289 @@
//
// BindWatchPopView.m
// XinjiangProject
//
// Created by Apple on 2026/3/12.
//
#import "BindWatchPopView.h"
@interface BindWatchPopView ()
@property (nonatomic,strong) UIView *bottomView;
@property (nonatomic,strong) UITextField *workNoField;
@property (nonatomic,strong) UITextField *nameField;
@property (nonatomic,strong) UITextField *numberField;
@property (nonatomic,strong) UIButton *actionBtn;
@end
@implementation BindWatchPopView
- (instancetype)initWithFrame:(CGRect)frame {
if (self = [super initWithFrame:frame]) {
self.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.4];
[self createUI];
[self addGesture];
[self addKeyboardNotification];
}
return self;
}
#pragma mark - UI
- (void)createUI {
self.bottomView = [[UIView alloc] init];
self.bottomView.backgroundColor = UIColor.whiteColor;
self.bottomView.layer.cornerRadius = 16;
self.bottomView.layer.maskedCorners = kCALayerMinXMinYCorner | kCALayerMaxXMinYCorner;
self.bottomView.layer.masksToBounds = YES;
[self addSubview:self.bottomView];
[self.bottomView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.right.bottom.offset(0);
make.height.offset(342);
}];
/// 拖动条
UIView *indicator = [[UIView alloc] init];
indicator.backgroundColor = UIColorHex(#D8D8D8);
indicator.layer.cornerRadius = 3;
[self.bottomView addSubview:indicator];
[indicator mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerX.offset(0);
make.top.offset(8);
make.width.offset(40);
make.height.offset(6);
}];
UILabel *titleLab = [[UILabel alloc] init];
titleLab.text = @"健康监测";
titleLab.font = [UIFont boldSystemFontOfSize:16];
titleLab.textAlignment = NSTextAlignmentCenter;
[self.bottomView addSubview:titleLab];
[titleLab mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.right.offset(0);
make.top.offset(28);
}];
HQUserInfo * user = [HQCommonUtils keyedUnarchiverWithKey:LoginUserInfo];
self.workNoField = [self createTextField];
[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 *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)) {
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.backgroundColor = KWhiteColor;
[self.bottomView addSubview:self.numberField];
[self.numberField mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.right.height.equalTo(self.workNoField);
make.top.equalTo(self.nameField.mas_bottom).offset(16);
}];
UILabel *xulieLab = [self createLabel:@"序列号:"];
[self.bottomView addSubview:xulieLab];
[xulieLab mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.offset(0);
make.right.equalTo(self.numberField.mas_left);
make.centerY.equalTo(self.numberField);
}];
UIButton *bindBtn = [[UIButton alloc] init];
[bindBtn setTitle:@"解绑" forState:UIControlStateNormal];
bindBtn.backgroundColor = UIColorHex(#21BEBD);
bindBtn.layer.cornerRadius = 22;
bindBtn.titleLabel.font = [UIFont boldSystemFontOfSize:16];
[bindBtn addTarget:self action:@selector(bindwatchClick:) forControlEvents:UIControlEventTouchUpInside];
self.actionBtn = bindBtn;
[self.bottomView addSubview:bindBtn];
[bindBtn mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerX.offset(0);
make.width.offset(215);
make.height.offset(44);
make.top.equalTo(self.numberField.mas_bottom).offset(30);
}];
}
- (void)updateUI {
if (self.type == BindWatchTypeUnbind) {
[self.actionBtn setTitle:@"解绑" forState:UIControlStateNormal];
self.numberField.text = self.serialNumber;
self.numberField.enabled = NO;
} else {
[self.actionBtn setTitle:@"绑定" forState:UIControlStateNormal];
self.numberField.text = @"";
self.numberField.enabled = YES;
}
}
- (void)bindwatchClick:(UIButton *)btn {
NSString *number = self.numberField.text;
if (self.actionBlock) {
self.actionBlock(self.type, number);
}
[self close];
}
#pragma mark - 创建控件
- (UILabel *)createLabel:(NSString *)text {
UILabel *lab = [[UILabel alloc] init];
lab.text = text;
lab.font = [UIFont systemFontOfSize:16];
lab.textAlignment = NSTextAlignmentCenter;
return lab;
}
- (UITextField *)createTextField {
UITextField *field = [[UITextField alloc] init];
field.backgroundColor = UIColorHex(#F5F7FB);
field.layer.cornerRadius = 8;
field.layer.borderWidth = 1;
field.layer.borderColor = UIColorHex(#E6E6EA).CGColor;
UIView *leftView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 12, 52)];
field.leftView = leftView;
field.leftViewMode = UITextFieldViewModeAlways;
return field;
}
#pragma mark - 点击背景关闭
- (void)addGesture {
// UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(close)];
// tap.cancelsTouchesInView = NO;
// [self addGestureRecognizer:tap];
}
- (void)close {
[self endEditing:YES];
[UIView animateWithDuration:0.25 animations:^{
self.bottomView.transform = CGAffineTransformMakeTranslation(0, 342);
self.alpha = 0;
} completion:^(BOOL finished) {
[self removeFromSuperview];
}];
}
#pragma mark - 键盘
- (void)addKeyboardNotification {
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardShow:) name:UIKeyboardWillShowNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardHide:) name:UIKeyboardWillHideNotification object:nil];
}
- (void)keyboardShow:(NSNotification *)noti {
CGRect rect = [noti.userInfo[UIKeyboardFrameEndUserInfoKey] CGRectValue];
CGFloat keyboardH = rect.size.height;
[UIView animateWithDuration:0.25 animations:^{
self.bottomView.transform = CGAffineTransformMakeTranslation(0, -keyboardH);
}];
}
- (void)keyboardHide:(NSNotification *)noti {
[UIView animateWithDuration:0.25 animations:^{
self.bottomView.transform = CGAffineTransformIdentity;
}];
}
#pragma mark - show
- (void)show {
[self updateUI];
UIWindow *window = UIApplication.sharedApplication.keyWindow;
self.frame = window.bounds;
[window addSubview:self];
self.bottomView.transform = CGAffineTransformMakeTranslation(0, 342);
[UIView animateWithDuration:0.25 animations:^{
self.bottomView.transform = CGAffineTransformIdentity;
}];
}
- (void)dealloc {
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
@end