From bfdf208899d7bef2abb499ad82f6e0a63699b3d6 Mon Sep 17 00:00:00 2001 From: wbzhan Date: Mon, 30 Sep 2019 13:30:50 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=8D=A2=E7=83=AD=E7=82=B9=E9=93=BE?= =?UTF-8?q?=E6=8E=A5=E6=96=B9=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ConnectAauariumVC/ConAquarChooseWiFiVC.m | 18 +- .../ConnectAauariumVC/ConAquarNowWiFiPwdVC.h | 3 +- .../ConnectAauariumVC/ConAquarNowWiFiPwdVC.m | 10 +- .../ConnectAauariumVC/ConnectingAquarVC.h | 2 + .../ConnectAauariumVC/ConnectingAquarVC.m | 202 +++++++++++++++++- Ifish/controllers/HotBar/IfishHotBarVc.m | 12 +- .../HotBar/Views/IFishHotBarCell.m | 4 +- .../SecondConnectWifiController.m | 5 +- Ifish/views/HKPieChartView/HKPieChartView.h | 2 +- Ifish/views/HKPieChartView/HKPieChartView.m | 63 +++--- 10 files changed, 259 insertions(+), 62 deletions(-) diff --git a/Ifish/controllers/ConnectAauariumVC/ConAquarChooseWiFiVC.m b/Ifish/controllers/ConnectAauariumVC/ConAquarChooseWiFiVC.m index d745c4c..fcf84fc 100644 --- a/Ifish/controllers/ConnectAauariumVC/ConAquarChooseWiFiVC.m +++ b/Ifish/controllers/ConnectAauariumVC/ConAquarChooseWiFiVC.m @@ -37,9 +37,9 @@ Assign BOOL isGoChangeWiFi;//更换为设备的WiFi [self.connectWiFiBtn mas_makeConstraints:^(MASConstraintMaker *make) { make.centerX.mas_equalTo(self.view); - make.bottom.mas_equalTo(-kSizeFrom750(60)); - make.width.mas_equalTo(kSizeFrom750(400)); - make.height.mas_equalTo(kSizeFrom750(60)); + make.bottom.mas_equalTo(-30); + make.width.mas_equalTo(200); + make.height.mas_equalTo(30); }]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(viewWillEnterForeground:) name:Noti_WillEnterForeground object:nil]; @@ -100,17 +100,17 @@ Assign BOOL isGoChangeWiFi;//更换为设备的WiFi } } -(void)checkWiFi{ -// NSDictionary *ifs = [self getSSIDInfo]; -// NSString *wifiName = [ifs objectForKey:@"SSID"]; -// if ([wifiName rangeOfString:@"ifish-"].location!=NSNotFound) { + NSDictionary *ifs = [self getSSIDInfo]; + NSString *wifiName = [ifs objectForKey:@"SSID"]; + if ([wifiName rangeOfString:@"ifish-"].location!=NSNotFound) { //wifi正确,则尝试连接设备 ConnectingAquarVC *connecting = InitObject(ConnectingAquarVC); connecting.wifiName = self.wifiName; connecting.wifiPassword = self.wifiPwd; [self.navigationController pushViewController:connecting animated:YES]; -// }else{ -// [self.view makeToast:@"WiFi名称不匹配,请重试"]; -// } + }else{ + [self.view makeToast:@"WiFi名称不匹配,请重试"]; + } } - (id)getSSIDInfo diff --git a/Ifish/controllers/ConnectAauariumVC/ConAquarNowWiFiPwdVC.h b/Ifish/controllers/ConnectAauariumVC/ConAquarNowWiFiPwdVC.h index deca40a..0dce54f 100644 --- a/Ifish/controllers/ConnectAauariumVC/ConAquarNowWiFiPwdVC.h +++ b/Ifish/controllers/ConnectAauariumVC/ConAquarNowWiFiPwdVC.h @@ -14,7 +14,8 @@ NS_ASSUME_NONNULL_BEGIN 输入当前wifi密码页面 */ @interface ConAquarNowWiFiPwdVC : BaseViewController - +Copy NSString *ssid; +Copy NSString *bssid; @end NS_ASSUME_NONNULL_END diff --git a/Ifish/controllers/ConnectAauariumVC/ConAquarNowWiFiPwdVC.m b/Ifish/controllers/ConnectAauariumVC/ConAquarNowWiFiPwdVC.m index b76ff02..92de5bd 100644 --- a/Ifish/controllers/ConnectAauariumVC/ConAquarNowWiFiPwdVC.m +++ b/Ifish/controllers/ConnectAauariumVC/ConAquarNowWiFiPwdVC.m @@ -159,8 +159,8 @@ Strong UIButton *nextBtn; [self.nextBtn mas_makeConstraints:^(MASConstraintMaker *make) { make.centerX.mas_equalTo(self.view); make.top.mas_equalTo(self.wifiPwdTextField.mas_bottom).offset(kSizeFrom750(100)); - make.width.mas_equalTo(kSizeFrom750(400)); - make.height.mas_equalTo(kSizeFrom750(55)); + make.width.mas_equalTo(200); + make.height.mas_equalTo(30); }]; [self addContentLabel];; @@ -207,6 +207,12 @@ Strong UIButton *nextBtn; } #pragma mark --buttonClick -(void)nextBtnClick:(UIButton *)sender{ + BOOL isRight =[dataContorl isIncludeSpecialCharact:self.wifiPwdTextField.text]; + + if (!isRight) { + [self.view makeToast:@"路由器密码不能包含特殊字符,只能为数字、字母或下划线"]; + return; + } ConAquarChooseWiFiVC *chooseVC = InitObject(ConAquarChooseWiFiVC); chooseVC.wifiName = self.wifiNameTextField.text; chooseVC.wifiPwd = self.wifiPwdTextField.text; diff --git a/Ifish/controllers/ConnectAauariumVC/ConnectingAquarVC.h b/Ifish/controllers/ConnectAauariumVC/ConnectingAquarVC.h index 2341c4e..482be4e 100644 --- a/Ifish/controllers/ConnectAauariumVC/ConnectingAquarVC.h +++ b/Ifish/controllers/ConnectAauariumVC/ConnectingAquarVC.h @@ -16,6 +16,8 @@ NS_ASSUME_NONNULL_BEGIN @interface ConnectingAquarVC : BaseViewController Copy NSString *wifiName;//设备要连接的WiFi名称 Copy NSString *wifiPassword;//智能设备要连接的WiFi密码 +Copy NSString *ssid; +Copy NSString *bssid; @end NS_ASSUME_NONNULL_END diff --git a/Ifish/controllers/ConnectAauariumVC/ConnectingAquarVC.m b/Ifish/controllers/ConnectAauariumVC/ConnectingAquarVC.m index 480852b..5371948 100644 --- a/Ifish/controllers/ConnectAauariumVC/ConnectingAquarVC.m +++ b/Ifish/controllers/ConnectAauariumVC/ConnectingAquarVC.m @@ -14,12 +14,14 @@ #import "ESPTouchResult.h" #import "ESPTouchTask.h" #import "IfishDataUnity.h" -#import -@interface ConnectingAquarVC () +//#import +@interface ConnectingAquarVC () Strong HKPieChartView *progressView; Strong UILabel *titleL; Strong ESPTouchTask* epTask; Strong NSMutableString *trackString; +Strong MBProgressHUD *HUD; +Strong NSTimer *timer; /** 设备返回的mac地址 */ @@ -48,21 +50,33 @@ Assign NSInteger retryTimes; make.centerX.mas_equalTo(self.view); make.width.mas_equalTo(kSizeFrom750(700)); }]; - [self.progressView updatePercent:99 animation:YES]; + [self.progressView updatePercent:100 animation:YES]; //AP模式配网 - [[GWP2PDeviceLinker shareInstance] p2pAPLinkDeviceWithWiFiSSID:self.wifiName wifiPassword:self.wifiPassword devicePassword:@"123" deviceReceive:^(NSString *deviceId, BOOL isSupport) { - // - NSLog(@"设备%@收到WiFi,isSupport:%d",deviceId,isSupport); - } deviceLinkIn:^(NSDictionary *deviceDict) { - //成功 - }]; - +// [[GWP2PDeviceLinker shareInstance] p2pAPLinkDeviceWithWiFiSSID:self.wifiName wifiPassword:self.wifiPassword devicePassword:@"123" deviceReceive:^(NSString *deviceId, BOOL isSupport) { +// // +// NSLog(@"设备%@收到WiFi,isSupport:%d",deviceId,isSupport); +// } deviceLinkIn:^(NSDictionary *deviceDict) { +// //成功 +// }]; + //传入设备要连接的wifi名称和密码 + // [self sendToDeviceWithSSIDName:self.wifiName andSSIDPWD:self.wifiPassword]; // Do any additional setup after loading the view. + + self.timer = [NSTimer timerWithTimeInterval:1 target:self selector:@selector(timerAction) userInfo:nil repeats:YES]; + [[NSRunLoop currentRunLoop] addTimer:self.timer forMode:NSRunLoopCommonModes]; +} +- (void)dealloc +{ + if (!self.timer) { + return; + } + [self.timer invalidate]; + self.timer = nil; } - (HKPieChartView *)progressView { if (!_progressView) { - _progressView = [[HKPieChartView alloc]initWithFrame:RECT((screen_width - 100)/2, 120, 100, 100)]; + _progressView = [[HKPieChartView alloc]initWithFrame:RECT((screen_width - 100)/2, 100, 100, 100)]; } return _progressView; } @@ -78,6 +92,172 @@ Assign NSInteger retryTimes; } return _titleL; } +-(void)timerAction{ + [self.progressView updatePercent:100 animation:YES]; +} +#pragma mark - UDP related + +- (NSString *)currentWifiSSID { + NSString *ssid = @"Not Found"; + CFArrayRef myArray = CNCopySupportedInterfaces(); + if (myArray != nil) { + CFDictionaryRef myDict = CNCopyCurrentNetworkInfo(CFArrayGetValueAtIndex(myArray, 0)); + if (myDict != nil) { + NSDictionary *dict = (NSDictionary *)CFBridgingRelease(myDict); + ssid = [dict valueForKey:@"SSID"]; + } + } + return ssid; +} + +- (void)sendToDeviceWithSSIDName:(NSString *)name andSSIDPWD:(NSString *)pwd { + [IFishHotpotUDPHelper sharedInstance].delegate = self; + [[IFishHotpotUDPHelper sharedInstance] broadCastHotspotConnectCommandWith:name pwd:pwd]; +} + +#pragma mark - IFishHotpotUDPHelperDelegate + +- (void)udpHelperCommandExecutedSuccess:(IFishUDPHelperBackMsgModel *)backModel { + self.ssid = backModel.senderMacAddress; + [self.view resignFirstResponder]; + self.HUD.labelText = @"请稍后"; + self.trackString = [NSMutableString string]; + [self appendTrakContent:@"=================收到设备答复==================="]; + [self appendTrakContent:[NSString stringWithFormat:@"答复状态码:%@", backModel.result]]; + [self appendTrakContent:[NSString stringWithFormat:@"答复Mac地址:%@", backModel.senderMacAddress]]; + self.macAddress = backModel.senderMacAddress; + + [IFishHotpotUDPHelper sharedInstance].delegate = nil; + [[IFishHotpotUDPHelper sharedInstance] broadCastRestartCommand]; + self.bindTimer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(startBinding) userInfo:nil repeats:YES]; +} + +- (void)startBinding { + BOOL networkOk = NO; + AFNetworkReachabilityStatus status = [AFNetworkReachabilityManager sharedManager].networkReachabilityStatus; + if (status == AFNetworkReachabilityStatusReachableViaWiFi) { + if (![[self currentWifiSSID].lowercaseString hasPrefix:@"ifish"]) { + networkOk = YES; + } + } else if (status == AFNetworkReachabilityStatusReachableViaWWAN) { + networkOk = YES; + } + if (!networkOk) { + return; + } + if (self.isBindingDevice) { + return; + } + if (self.macAddress.length == 0) { + return; + } + self.isBindingDevice = YES; + if (self.bindTimer) { + [self.bindTimer invalidate]; + self.bindTimer = nil; + } + self.retryTimes = 0; + [self bindDeviceWithSsid:self.macAddress]; +} + +- (void)udpHelperMessage:(NSString *)msg { + self.HUD = [MBProgressHUD showHUDAddedTo:self.view animated:YES]; + self.HUD.mode = MBProgressHUDModeIndeterminate; + self.HUD.labelText = msg; +} + +#pragma mark - bind +-(void)bindDeviceWithSsid:(NSString*)bssid{ + NSLog(@"设备bssid_%@",bssid); + [self appendTrakContent:@"=================进入绑定函数================="]; + NSString *userId = [dataContorl dataControlGetUserIdInfo]; + self.HUD.labelText = @"正在绑定设备"; + [self appendTrakContent:[NSString stringWithFormat:@"绑定参数 userID:%@", userId]]; + [self appendTrakContent:[NSString stringWithFormat:@"绑定参数 macaddress:%@", bssid]]; + [AFHttpTool bindDeviceWithUserId:userId macAddress:bssid success:^(id response) { + [self.progressView endEditing:YES]; + self.isBindingDevice = NO; + self.macAddress = nil; + [self.progressView endProgressWithString:@"连接结束"]; + [self.timer invalidate]; + self.timer = nil; + NSDictionary*resultDic=[NSJSONSerialization JSONObjectWithData:response options:NSJSONReadingMutableContainers error:nil]; + NSLog(@"data:%@",resultDic[@"data"]); + [self appendTrakContent:[NSString stringWithFormat:@"绑定请求成功。返回数据为:%@", resultDic]]; + if ([resultDic[@"result"] isEqualToString:@"100"]) { + + // 保存设备信息 + NSDictionary*dataDic=resultDic[@"data"]; + DeviceModel*devicemodel=[[DeviceModel alloc] initWithDict:dataDic]; + [self appendTrakContent:[NSString stringWithFormat:@"绑定返回状态码正确。设备信息为:%@", dataDic]]; + + if (!devicemodel.type){ + self.HUD.labelText = @"用户绑定设备成功,但设备初次入网失败请重新登陆"; + + }else{ + NSMutableArray * _deviceArry=[[DataCenter defaultDtacenter]valueForKey:@"deviceInfo"]; + + [_deviceArry insertObject:devicemodel atIndex:0]; + + [[DataCenter defaultDtacenter]setValue:_deviceArry forKey:@"deviceInfo"]; + + if ([devicemodel.type isEqual:[NSNull null]]){ + + //进入此循环 可能因为设备所在服务器 不在 本程序所在 服务器 + self.HUD.labelText = @"设备不在服务器"; + + }else{ + + self.HUD.labelText = @"设备绑定成功"; + [[IfishDataUnity shareDataInstance] initAppCenterVcWith:devicemodel addWithdissMisVc:nil]; + + //绑定成功 加 经验值 + [[IfishUserObsever sharedInstance] xinZengJingYanZhi:IFISHADDEXP_BIDDEVICE addType:IFISHADDEXPTYPE1]; + } + } + + }else if ([resultDic[@"result"] isEqualToString:@"101"]){ + [self appendTrakContent:@"绑定返回状态码错误。设备信息为:%@"]; + self.HUD.labelText = @"绑定失败"; + self.bakbutton.userInteractionEnabled=YES; + + }else if ([resultDic[@"result"] isEqualToString:@"301"]){ + [self appendTrakContent:@"绑定返回状态码错误。设备信息为:%@"]; + + self.HUD.labelText = @"请求验证失败,请重新登录"; + self.bakbutton.userInteractionEnabled=YES; + }else if ([resultDic[@"result"] isEqualToString:@"302"]){ + // 请求被舍弃未执行 + [self appendTrakContent:@"绑定返回状态码错误。设备信息为:%@"]; + + self.bakbutton.userInteractionEnabled=YES; + self.HUD.labelText = @"绑定失败"; + [self.HUD hide:YES afterDelay:2]; + } + + + } failure:^(NSError *err) { + if (self.retryTimes < 3) { + [self bindDeviceWithSsid:self.macAddress]; + self.retryTimes += 1; + } else { + self.isBindingDevice = NO; + self.HUD.labelText = @"请求异常"; + [self.HUD hide:YES afterDelay:2]; + [self appendTrakContent:[NSString stringWithFormat:@"绑定网络请求错误:%@", err.localizedDescription]]; + self.bakbutton.userInteractionEnabled=YES; + } + }]; + +} + +#pragma mark - Private + +- (void)appendTrakContent:(NSString *)msg { + [self.trackString appendString:msg]; + [self.trackString appendString:@"\n"]; +} + /* #pragma mark - Navigation diff --git a/Ifish/controllers/HotBar/IfishHotBarVc.m b/Ifish/controllers/HotBar/IfishHotBarVc.m index dd140c3..eabab4a 100644 --- a/Ifish/controllers/HotBar/IfishHotBarVc.m +++ b/Ifish/controllers/HotBar/IfishHotBarVc.m @@ -172,7 +172,7 @@ Assign BOOL isInitHostoryView; temp=[temp stringByReplacingOccurrencesOfString:@"°c" withString:@""]; IfishHotBarVo*vo=self.datas[0]; self.vo.heaterNum=[NSString stringWithFormat:@"%f",temp.floatValue]; - vo.title=[NSString stringWithFormat:@"设置温度 %.1f°c",[self.vo.heaterNum floatValue]]; + vo.subTitle=[NSString stringWithFormat:@"%.1f°c",[self.vo.heaterNum floatValue]]; [self.mainTableView reloadData]; [self setHeatTeapWith:temp]; } @@ -367,6 +367,8 @@ Assign BOOL isInitHostoryView; self.historyView.datas=self.vo.phs; self.historyView.hidden=YES; } + + //去除鱼缸容积 IfishHotBarVo*vo1=self.datas[4]; if (self.vo.heater.heaterCycle.length) { @@ -473,9 +475,13 @@ Assign BOOL isInitHostoryView; self.vo.heaterNum=[NSString stringWithFormat:@"%f",num]; IfishHotBarVo*vo=self.datas[0]; - vo.title=[NSString stringWithFormat:@"设置温度 %.1f°c",[self.vo.heaterNum floatValue]]; - + vo.subTitle=[NSString stringWithFormat:@"%.1f°c",[self.vo.heaterNum floatValue]]; + //设置预警温度区间 + IfishHotBarVo*vo1=self.datas[1]; + if (!IsEmptyStr(self.vo.upTeamp)) { + vo1.subTitle = [NSString stringWithFormat:@"%.1f°c到%.1f°c",[self.vo.downTeamp floatValue],[self.vo.upTeamp floatValue]]; + } self.vo.wornCode=[info substringWithRange:NSMakeRange(44, 2)]; // self.vo.wornCode=[NSString stringWithFormat:@"%llu",[dataContorl hexToTen:self.vo.wornCode]]; diff --git a/Ifish/controllers/HotBar/Views/IFishHotBarCell.m b/Ifish/controllers/HotBar/Views/IFishHotBarCell.m index a8fce39..92bd7bd 100644 --- a/Ifish/controllers/HotBar/Views/IFishHotBarCell.m +++ b/Ifish/controllers/HotBar/Views/IFishHotBarCell.m @@ -40,10 +40,10 @@ self.subTitleLable.text=vo.subTitle; self.iconImgV.image=[UIImage imageNamed:vo.iconUrl]; self.arrowImgV.hidden=!vo.isShowArrow; - if (vo.phv!=499) {//无水 + [self.subTitleLable setTextColor:[UIColor colorWithRed:109/255.0 green:109/255.0 blue:109/255.0 alpha:1.0]]; + if ((vo.phv!=499)&&[vo.title isEqualToString:@"水泵流量"]) {//水泵流量无水 [self.subTitleLable setTextColor:[UIColor redColor]]; }else{//正常 - [self.subTitleLable setTextColor:[UIColor colorWithRed:109/255.0 green:109/255.0 blue:109/255.0 alpha:1.0]]; } } diff --git a/Ifish/controllers/leftcontrollers/SecondConnectWifiController.m b/Ifish/controllers/leftcontrollers/SecondConnectWifiController.m index 215d039..086dee9 100644 --- a/Ifish/controllers/leftcontrollers/SecondConnectWifiController.m +++ b/Ifish/controllers/leftcontrollers/SecondConnectWifiController.m @@ -29,7 +29,7 @@ #import "IfishUserObsever.h" #import "ConnectHotpotViewController.h" - +#import "ConAquarNowWiFiPwdVC.h" @interface EspTouchDelegateImpl : NSObject @end @@ -424,7 +424,8 @@ extern BOOL isfromCameraView; } - (IBAction)lickHereBtnClicked:(id)sender { - ConnectHotpotViewController *vc = [[ConnectHotpotViewController alloc] init]; +// ConnectHotpotViewController *vc = [[ConnectHotpotViewController alloc] init]; + ConAquarNowWiFiPwdVC *vc = [[ConAquarNowWiFiPwdVC alloc]init]; vc.ssid = self.ssid; vc.bssid = self.bssid; [self.navigationController pushViewController:vc animated:YES]; diff --git a/Ifish/views/HKPieChartView/HKPieChartView.h b/Ifish/views/HKPieChartView/HKPieChartView.h index 2057987..26ec04a 100755 --- a/Ifish/views/HKPieChartView/HKPieChartView.h +++ b/Ifish/views/HKPieChartView/HKPieChartView.h @@ -11,5 +11,5 @@ @interface HKPieChartView : UIView @property (nonatomic, assign) BOOL inCounting; - (void)updatePercent:(CGFloat)percent animation:(BOOL)animationed; - +- (void)endProgressWithString:(NSString *)text; @end diff --git a/Ifish/views/HKPieChartView/HKPieChartView.m b/Ifish/views/HKPieChartView/HKPieChartView.m index 629c3b3..ee8e211 100755 --- a/Ifish/views/HKPieChartView/HKPieChartView.m +++ b/Ifish/views/HKPieChartView/HKPieChartView.m @@ -7,8 +7,8 @@ // #import "HKPieChartView.h" -#define cycle_blue RGB(174, 191, 228) -#define cycle_green RGB(66, 116, 130) +#define Cycle_DarkBlue RGB(0, 150, 200) +#define Cycle_LightBlue RGB(160, 200, 255) @interface HKPieChartView() @property (nonatomic, strong) CAShapeLayer *trackLayer; @@ -48,10 +48,9 @@ } - (void)updateUI { - // self.trackColor = RGB(240, 244, 251); self.trackColor = [UIColor clearColor]; - self.progressColor = cycle_green; - self.animationDuration = 100; + self.progressColor = Cycle_DarkBlue; + self.animationDuration = 1; self.pathWidth = self.frame.size.width - kSizeFrom750(8); [self shadowImageView]; @@ -59,7 +58,9 @@ [self gradientLayer]; [self loadGesture]; } - +- (void)endProgressWithString:(NSString *)text{ + self.progressLabel.text = text; +} - (void)dealloc { [self invalidateTimer]; } @@ -117,12 +118,11 @@ CABasicAnimation *animation= [CABasicAnimation animationWithKeyPath:@"strokeEnd"]; animation.fromValue = @(0.0); - animation.toValue = @(self.percent / 100.); + animation.toValue = @(self.percent / 100.f); animation.duration = self.animationDuration * self.percent / 100; animation.removedOnCompletion = YES; animation.delegate = self; animation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn]; - self.progressLayer.strokeEnd = self.percent / 100; [self.progressLayer addAnimation:animation forKey:@"strokeEndAnimation"]; } @@ -131,20 +131,20 @@ #pragma mark - CAAnimationDelegate - (void)animationDidStart:(CAAnimation *)anim { - self.timer = [NSTimer timerWithTimeInterval:1/60 target:self selector:@selector(timerAction) userInfo:nil repeats:YES]; - [[NSRunLoop currentRunLoop] addTimer:self.timer forMode:NSRunLoopCommonModes]; + self.progressLabel.text = @"设备连接中..."; + } - (void)animationDidStop:(CAAnimation *)anim finished:(BOOL)flag { - if (flag) { - [self invalidateTimer]; - if (self.inCounting&&self.percent==0) { - self.progressLabel.text = @"未开始"; - }else - { - self.progressLabel.text = [NSString stringWithFormat:@"%.0f%%", self.percent]; - } - } +// if (flag) { +// [self invalidateTimer]; +// if (self.inCounting&&self.percent==0) { +// self.progressLabel.text = @"未开始"; +// }else +// { +// self.progressLabel.text = [NSString stringWithFormat:@"%.0f%%", self.percent]; +// } +// } } - (void)timerAction { @@ -157,7 +157,11 @@ self.progressLabel.text = @"未开始"; }else { - self.progressLabel.text = [NSString stringWithFormat:@"%0.f%%",floorf(progress * 100)]; + NSLog(@"%.2f",progress); + self.progressLabel.text = [NSString stringWithFormat:@"%.0f%%",floorf(progress * 100)]; + if (progress>0.5) { + [self updatePercent:100 animation:NO]; + } } } @@ -189,12 +193,11 @@ CGFloat radius = (self.frame.size.width- kSizeFrom750(8)*2)/2; CGFloat startA = -M_PI_2; //设置进度条起点位置 CGFloat endA =-M_PI_2+ M_PI * 2; //设置进度条终点位置 - //获取环形路径(画一个圆形,填充色透明,设置线框宽度为10,这样就获得了一个环形) CAShapeLayer * _backLayer = [CAShapeLayer layer];//创建一个track shape layer _backLayer.frame = self.bounds; _backLayer.fillColor = [[UIColor clearColor] CGColor]; //填充色为无色 - _backLayer.strokeColor = [cycle_blue CGColor]; //指定path的渲染颜色,这里可以设置任意不透明颜色-淡蓝色 + _backLayer.strokeColor = [Cycle_LightBlue CGColor]; //指定path的渲染颜色,这里可以设置任意不透明颜色-淡蓝色 _backLayer.opacity = 1; //背景颜色的透明度 _backLayer.lineCap = kCALineCapRound;//指定线的边缘是圆的 _backLayer.lineWidth = kSizeFrom750(8);//线的宽度 @@ -220,12 +223,10 @@ if (!_gradientLayer) { _gradientLayer = [CAGradientLayer layer]; _gradientLayer.frame = self.bounds; - _gradientLayer.borderColor = cycle_green.CGColor; - // _gradientLayer.colors = @[(id)[UIColor cyanColor].CGColor, - // (id)[UIColor colorWithRed:0.000 green:0.502 blue:1.000 alpha:1.000].CGColor]; -// _gradientLayer.colors = @[(id)HEXCOLOR(@"#4294f8").CGColor,(id)HEXCOLOR(@"#3b82f6").CGColor]; -// [_gradientLayer setStartPoint:CGPointMake(0.5, 1.0)]; -// [_gradientLayer setEndPoint:CGPointMake(0.5, 0.0)]; +// _gradientLayer.colors = @[(id)Cycle_DarkBlue.CGColor,(id)HEXCOLOR(@"#3b82f6").CGColor]; + _gradientLayer.colors = @[(id)Cycle_DarkBlue.CGColor,(id)Cycle_DarkBlue.CGColor]; + [_gradientLayer setStartPoint:CGPointMake(0.5, 1.0)]; + [_gradientLayer setEndPoint:CGPointMake(0.5, 0.0)]; [_gradientLayer setMask:self.progressLayer]; [self.layer addSublayer:_gradientLayer]; @@ -237,10 +238,10 @@ - (UILabel *)progressLabel { if (!_progressLabel) { _progressLabel = [[UILabel alloc]initWithFrame:self.bounds]; - _progressLabel.textColor = cycle_green; + _progressLabel.textColor = Cycle_DarkBlue; _progressLabel.textAlignment = NSTextAlignmentCenter; - _progressLabel.font = FontSize(18); - + _progressLabel.font = FontSize(14); + _progressLabel.text = @"设备连接中..."; [self addSubview:_progressLabel]; } return _progressLabel;