// // LocationModeViewController.m // watch // // Created by xTT on 2017/7/17. // Copyright © 2017年 xTT. All rights reserved. // #import "LocationModeViewController.h" @interface LocationModeViewController () @property (nonatomic ,strong) NSArray *timeArr; @property (nonatomic ,strong) NSMutableArray *btnArr; @property (nonatomic ,strong) UIView *headerView; @property (nonatomic ,weak) UISwitch *customSwitch; @property (nonatomic ,weak) UIView *bgView; @end @implementation LocationModeViewController @synthesize myDataSource = _myDataSource; - (NSMutableArray *)myDataSource{ if (!_myDataSource) { //_myDataSource = [[NSMutableArray alloc] initWithArray:@[@[@"省电模式",@"正常模式",@"高频模式"]]]; // MARK: 从后台获取值显示 update by lsz 2021-06-23 _myDataSource = [[NSMutableArray alloc] initWithArray:@[cUser.cDevice.location_model1,cUser.cDevice.location_model2,cUser.cDevice.location_model3]]; } return _myDataSource; } - (NSNumber *)locationMode{ if (!_locationMode) { if ([cUser.cDevice.opLocationMode intValue] < 3) { _locationMode = cUser.cDevice.location_interval2; } else { _locationMode = cUser.cDevice.opLocationMode; } } return _locationMode; } - (void)viewDidLoad { [super viewDidLoad]; self.zx_navTitle = @"设置"; self.timeArr = @[cUser.cDevice.location_interval1, cUser.cDevice.location_interval2, cUser.cDevice.location_interval3]; [self.view addSubview:self.headerView]; NSLog(@"%@",self.locationMode); UIView *bgView = [UICommon ui_view:CGRectMake(15, self.headerView.bottom+12, ScreenWidth-30, 318) backgroundColor:KKWhiteColorColor cornerRadius:12 borderWidth:0 borderColor:KKWhiteColorColor]; bgView.hidden = !cUser.cDevice.opGpsSwitch.boolValue; self.bgView = bgView; [self.view addSubview:bgView]; UILabel *titleLabel = [UICommon ui_label:CGRectZero lines:0 align:NSTextAlignmentCenter font:FontBold_(16) textColor:KKBlack20 text:@"定位模式" Radius:0]; [bgView addSubview:titleLabel]; [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.left.top.equalTo(bgView).offset(15); }]; UIImage *img = ImageName_(@"map_select_yes_icon"); self.btnArr = [NSMutableArray new]; NSMutableArray *imgArr = [NSMutableArray new]; for (int i = 0; i < self.timeArr.count; i++) { NSString *title = [NSString stringWithFormat:@"%@\n每%@分钟定位一次",self.myDataSource[i],self.timeArr[i]]; UIButton *button = [UICommon ui_buttonSimple:CGRectZero font:Font_(14) normalColor:KKGrey163 normalText:@"" click:^(UIButton *btn) { for (UIButton *butt in self.btnArr) { butt.backgroundColor = butt.tag == btn.tag ? RGBA(255, 94, 16, 0.08) : KKClearColor; butt.layer.borderColor = butt.tag == btn.tag ? mainColor.CGColor : RGB(240, 239, 237).CGColor; if (butt.tag == btn.tag) { self.locationMode = self.timeArr[btn.tag]; [self rightBarItemClick]; } } for (UIImageView *image in imgArr) { image.hidden = image.tag == btn.tag ? NO : YES; } }]; button.backgroundColor = self.locationMode.integerValue == [self.timeArr[i] integerValue] ? RGBA(255, 94, 16, 0.08) : KKClearColor; [button setContentHorizontalAlignment:UIControlContentHorizontalAlignmentLeft]; [button setAttributedTitle:[self labelFontSize:title :self.myDataSource[i]] forState:0]; [button setTitleEdgeInsets:UIEdgeInsetsMake(0, 15, 0, 0)]; button.layer.borderWidth = 1; button.layer.borderColor = self.locationMode.integerValue == [self.timeArr[i] integerValue] ? mainColor.CGColor : RGB(240, 239, 237).CGColor; button.layer.cornerRadius = 12; button.layer.masksToBounds = YES; button.titleLabel.numberOfLines = 0; button.tag = i; [bgView addSubview:button]; [button mas_makeConstraints:^(MASConstraintMaker *make) { make.left.right.equalTo(bgView).inset(15); make.top.equalTo(titleLabel.mas_bottom).offset(12+i*74+i*12); make.height.mas_equalTo(74); }]; [self.btnArr addObject:button]; UIImageView *rightImg = [UICommon ui_imageView:CGRectZero fileName:@"map_select_yes_icon"]; rightImg.tag = i; rightImg.hidden = self.locationMode.integerValue == [self.timeArr[i] integerValue] ? NO : YES; [bgView addSubview:rightImg]; [rightImg mas_makeConstraints:^(MASConstraintMaker *make) { make.right.equalTo(button.mas_right).inset(15); make.centerY.equalTo(button); make.size.mas_equalTo(rightImg.image.size); }]; [imgArr addObject:rightImg]; } } - (void)rightBarItemClick { WEAKSELF [cUser.cDevice editOperationDeviceInfoWithParameters:@{@"opLocationMode":self.locationMode} success:^(id responseObject) { cUser.cDevice.opLocationMode = weakSelf.locationMode; [[NSNotificationCenter defaultCenter] postNotificationName:@"UPDATADEVICE" object:nil]; } failure:^(id faiObject) { }]; } - (UIView *)headerView { if(!_headerView) { _headerView = [UICommon ui_view:CGRectZero backgroundColor:KKWhiteColorColor cornerRadius:12 borderWidth:0 borderColor:KKWhiteColorColor]; _headerView.frame = CGRectMake(15, iPhoneX_NavHeight+15, ScreenWidth-30, 80); UILabel *titleLabel = [UICommon ui_label:CGRectZero lines:0 align:NSTextAlignmentCenter font:FontBold_(16) textColor:KKBlack20 text:@"历史轨迹开关" Radius:0]; [_headerView addSubview:titleLabel]; [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(_headerView).offset(15); make.bottom.equalTo(_headerView.mas_centerY).inset(5); }]; UILabel *textsLabel = [UICommon ui_label:CGRectZero lines:0 align:NSTextAlignmentCenter font:Font_(12) textColor:KKGrey153 text:@"关闭后将无法查看孩子的历史轨迹" Radius:0]; [_headerView addSubview:textsLabel]; [textsLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(titleLabel.mas_left); make.top.equalTo(_headerView.mas_centerY).offset(5); }]; UISwitch *customSwitch = [[UISwitch alloc] init]; [customSwitch setOnTintColor:mainColor]; [customSwitch addTarget:self action:@selector(switchChange:) forControlEvents:UIControlEventValueChanged]; [customSwitch setOn:cUser.cDevice.opGpsSwitch.boolValue]; self.customSwitch = customSwitch; [_headerView addSubview:customSwitch]; [customSwitch mas_makeConstraints:^(MASConstraintMaker *make) { make.right.equalTo(_headerView.mas_right).inset(15); make.centerY.equalTo(_headerView); make.size.mas_equalTo(CGSizeMake(Adapted(45), 30)); }]; } return _headerView; } /** * 按钮切换事件监听回调方法 */ - (void) switchChange:(UISwitch*)sw { if(sw.on == YES) { NSLog(@"开关切换为开"); } else if(sw.on == NO) { NSLog(@"开关切换为关"); } [cUser setSwitchDataState:sw.on success:^(id responseObject) { //[SVProgressHUD showSuccessWithStatus:@"开启成功"]; cUser.cDevice.opGpsSwitch = [NSNumber numberWithBool:sw.on]; [[NSNotificationCenter defaultCenter] postNotificationName:@"UPDATADEVICE" object:nil]; self.bgView.hidden = !cUser.cDevice.opGpsSwitch.boolValue; } failure:^{ [self.customSwitch setOn:cUser.cDevice.opGpsSwitch]; }]; } /// 指定字符大小 /// @param text 内容 - (NSAttributedString *)labelFontSize:(NSString *)text :(NSString *)toText { NSRange symbolRange = [text rangeOfString:toText]; NSMutableAttributedString *string = [[NSMutableAttributedString alloc] initWithString:text]; if (symbolRange.location != NSNotFound) { NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init]; paragraphStyle.lineSpacing = 8; paragraphStyle.alignment = NSTextAlignmentLeft; [string addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, string.length)]; [string addAttribute:NSForegroundColorAttributeName value:KKBlack20 range:NSMakeRange(symbolRange.location, symbolRange.length)]; [string addAttribute:NSFontAttributeName value:FontBold_(16) range:NSMakeRange(symbolRange.location, symbolRange.length)]; } return string; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } /* #pragma mark - Navigation // In a storyboard-based application, you will often want to do a little preparation before navigation - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { // Get the new view controller using [segue destinationViewController]. // Pass the selected object to the new view controller. } */ @end