CalculatorViewController.m 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591
  1. #import "CalculatorViewController.h"
  2. #import <Masonry.h>
  3. #import "connectDeviceManager.h"
  4. #import "RSATool.h"
  5. @interface CalculatorViewController ()
  6. {
  7. UIView *bgView;/*引导视图*/
  8. }
  9. @property(nonatomic,copy)NSMutableString *curKeyToForgetPwd;//特殊符号进入忘记密码
  10. @end
  11. @implementation CalculatorViewController
  12. @synthesize pwd;
  13. #define BUTTON
  14. - (void)viewDidLoad {
  15. [super viewDidLoad];
  16. // Do any additional setup after loading the view, typically from a nib.
  17. self.view.backgroundColor=[UIColor blackColor];
  18. CGFloat mWidth=self.view.frame.size.width;
  19. CGFloat mHieght=self.view.frame.size.height;
  20. //加载button
  21. [self loadButtons:mWidth Hight:mHieght];
  22. //加载textField
  23. [self loadTextField:mWidth Hight:mHieght];
  24. //初始化Calculator
  25. _cl=[[Calculator alloc]init];
  26. /*加载引导视图*/
  27. BOOL haveOpenMask = [HWDataManager getBoolWithKey:Const_Mask_View_Open_Calcuator_Tips];
  28. if (haveOpenMask == NO){
  29. [self addGuideView];
  30. }
  31. [[connectDeviceManager shareInstance] RefreshThridMsg];
  32. _curKeyToForgetPwd = [NSMutableString new];
  33. }
  34. - (void)addGuideView{
  35. bgView = [[UIView alloc] init];
  36. [bgView setBackgroundColor:HW000000Color60];
  37. [self.view addSubview:bgView];
  38. [bgView mas_makeConstraints:^(MASConstraintMaker *make) {
  39. make.left.mas_equalTo(0);
  40. make.bottom.mas_equalTo(0);
  41. make.right.mas_equalTo(0);
  42. make.top.mas_equalTo(0);
  43. }];
  44. /*箭头视图*/
  45. UIImageView *flagImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"guide_open_calcu_flag1"]];
  46. [bgView addSubview:flagImageView];
  47. [flagImageView mas_makeConstraints:^(MASConstraintMaker *make) {
  48. make.right.mas_equalTo(-118.f);
  49. make.height.mas_equalTo(67);
  50. make.width.mas_equalTo(22);
  51. make.top.equalTo(_TF.mas_centerY).offset(40);
  52. }];
  53. /*不可点击btn*/
  54. UIButton *unableBtn = [[UIButton alloc] init];
  55. unableBtn.frame = CGRectMake(0, 0, 295, 64);
  56. NSString * curStr = NSLocalizedString(@"guide_set_open_calcula_guide_tips",nil);
  57. CGFloat curHeight = [curStr boundingRectWithSize:CGSizeMake(295 - 20 , 1000) options:(NSStringDrawingUsesLineFragmentOrigin) attributes:@{NSFontAttributeName:[UIFont boldSystemFontOfSize:14.f]} context:nil].size.height;
  58. if(curHeight < 50){
  59. curHeight = 50;
  60. }
  61. else{
  62. curHeight += 20;
  63. }
  64. // gradient
  65. CAGradientLayer *gl = [CAGradientLayer layer];
  66. gl.frame = CGRectMake(0,0,295,curHeight);
  67. gl.startPoint = CGPointMake(0, 0.5);
  68. gl.endPoint = CGPointMake(1, 0.5);
  69. gl.colors = @[(__bridge id)HW0CDEFDColor.CGColor, (__bridge id)HW058DFBColor.CGColor];
  70. gl.locations = @[@(0), @(1.0f)];
  71. [unableBtn.layer addSublayer:gl];
  72. [unableBtn setUserInteractionEnabled:NO];
  73. [unableBtn setTitle:curStr forState:(UIControlStateNormal)];
  74. [unableBtn setTitleColor:[UIColor whiteColor] forState:(UIControlStateNormal)];
  75. [unableBtn.titleLabel setFont:[UIFont systemFontOfSize:14.f]];
  76. [unableBtn.titleLabel setNumberOfLines:0];
  77. [unableBtn.layer setCornerRadius:curHeight/2.0];
  78. unableBtn.clipsToBounds = YES;
  79. [bgView addSubview:unableBtn];
  80. [unableBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  81. make.right.mas_equalTo(-20*AUTOSCALE);
  82. make.width.mas_equalTo(295);
  83. make.top.equalTo(flagImageView.mas_bottom).offset(-8);
  84. make.height.mas_equalTo(curHeight);
  85. }];
  86. unableBtn.contentEdgeInsets = UIEdgeInsetsMake(0,10, 0, 10);
  87. UIButton *knowBtn = [[UIButton alloc] init];
  88. [knowBtn setBackgroundColor:[UIColor clearColor]];
  89. [knowBtn.layer setCornerRadius:18.f];
  90. [knowBtn.layer setBorderColor:HWFFFFFFColor.CGColor];
  91. [knowBtn.layer setBorderWidth:1];
  92. [knowBtn setTitle:NSLocalizedString(@"guide_set_pwd_guide_know",nil) forState:(UIControlStateNormal)];
  93. [knowBtn setTitleColor:[UIColor whiteColor] forState:(UIControlStateNormal)];
  94. [knowBtn.titleLabel setFont:[UIFont systemFontOfSize:16]];
  95. [bgView addSubview:knowBtn];
  96. [knowBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  97. make.right.mas_equalTo(-29*AUTOSCALE);
  98. make.width.mas_equalTo(120);
  99. make.top.equalTo(unableBtn.mas_bottom).offset(15);
  100. make.height.mas_equalTo(36.f);
  101. }];
  102. [knowBtn addTarget:self
  103. action:@selector(knowBtnPressed)
  104. forControlEvents:(UIControlEventTouchUpInside)];
  105. }
  106. - (void)knowBtnPressed{
  107. [bgView removeFromSuperview];
  108. [HWDataManager setBoolWithKey:Const_Mask_View_Open_Calcuator_Tips value:YES];
  109. }
  110. #pragma mark ----样式设置----
  111. -(void)loadButtons:(CGFloat)mWidth Hight:(CGFloat)mHieght{
  112. CGFloat x=1;
  113. CGFloat y=mHieght-(((mWidth-5)/4)*5)-1 - 60;
  114. if(mHieght == 736 || mHieght == 667){//修改 8P手机UI问题
  115. y += 40;
  116. }
  117. NSArray *buttonArray=@[@"C",@"+/-",@"%",@"÷",@"7",@"8",@"9",@"×",@"4",@"5",@"6",@"—",@"1",@"2",@"3",@"+",@"0",@".",@"="];
  118. NSInteger buttonArrayID=0;
  119. for (int i=0; i<5; i++) {
  120. for (int j=0; j<(i==4?3:4); j++) {
  121. UIButton *button=[UIButton buttonWithType:UIButtonTypeCustom];
  122. button.frame=CGRectMake(x, y, (buttonArrayID==16?(mWidth-5)/4*2+1 - 13:(mWidth-5)/4 - 13), (mWidth-5)/4 - 13);
  123. button.layer.cornerRadius = ((mWidth-5)/4 - 13)/2;
  124. [button setTitle:[buttonArray objectAtIndex:buttonArrayID] forState:UIControlStateNormal];
  125. button.titleLabel.font=[UIFont systemFontOfSize:40];
  126. button.tag=100+buttonArrayID;
  127. [button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
  128. if (buttonArrayID%4==3||buttonArrayID==[buttonArray count]-1) {
  129. button.backgroundColor=HWEFA23BColor;
  130. }else if(buttonArrayID==16){
  131. //设置 0 Button 文字向右对齐
  132. [button setTitleEdgeInsets:UIEdgeInsetsMake(0, 0, 0, (mWidth-5)/4)];
  133. x+=((mWidth-5)/4)+1;
  134. button.backgroundColor=HW333333Color9;
  135. }else if(buttonArrayID<3){
  136. button.backgroundColor=HWA5A5A5Color;
  137. [button setTitleColor: [UIColor blackColor] forState:UIControlStateNormal] ;
  138. }else{
  139. button.backgroundColor=HW333333Color9;
  140. }
  141. [button addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
  142. [self.view addSubview:button];
  143. x+=((mWidth-5)/4)+1;
  144. buttonArrayID++;
  145. }
  146. x=1;
  147. y+=((mWidth-5)/4)+1;
  148. }
  149. }
  150. -(void)loadTextField:(CGFloat)mWidth Hight:(CGFloat)mHieght{
  151. CGFloat adjust_X = 20.0;
  152. _TF=[[UITextField alloc]initWithFrame:CGRectMake(10, 50, mWidth-20- adjust_X, mHieght-(((mWidth-5)/4)*5)-50)];
  153. _TF.tag=1000;
  154. _TF.textColor=[UIColor whiteColor];
  155. [_TF setEnabled:NO];
  156. _TF.textAlignment=NSTextAlignmentRight;
  157. _TF.adjustsFontSizeToFitWidth=YES;//自适应宽度
  158. _TF.text=@"0";
  159. _TF.font=[UIFont fontWithName:@"HelveticaNeue-Thin" size:80];
  160. [self.view addSubview:_TF];
  161. }
  162. #pragma mark ----button响应----
  163. //button响应方法
  164. -(void)buttonAction:(UIButton *)sender{
  165. [self removeTextFieldFormat];
  166. switch (sender.tag) {
  167. case 100:
  168. //清除
  169. if ([sender.titleLabel.text isEqualToString:@"AC"]) {
  170. [self buttonSymbolStyleReduction:sender];
  171. }
  172. self.TF.text=@"0";
  173. [sender setTitle:@"AC" forState:UIControlStateNormal];
  174. [self.cl calculatorEmpty];
  175. _curKeyToForgetPwd = [NSMutableString new];
  176. break;
  177. case 101:
  178. //正负转换
  179. [self getPlusMinus:self.TF.text];
  180. _curKeyToForgetPwd = [NSMutableString new];
  181. break;
  182. case 102:
  183. //百分比
  184. [self getPercentage:self.TF.text];
  185. break;
  186. case 103:
  187. //除
  188. [self execute];
  189. self.cl.exType=1;
  190. [self buttonSymbolStyleReduction:sender];
  191. [self buttonSymbolStyle:sender];
  192. _curKeyToForgetPwd = [NSMutableString new];
  193. break;
  194. case 107:
  195. //乘
  196. [self execute];
  197. self.cl.exType=2;
  198. [self buttonSymbolStyleReduction:sender];
  199. [self buttonSymbolStyle:sender];
  200. _curKeyToForgetPwd = [NSMutableString new];
  201. break;
  202. case 111:
  203. //减
  204. [self execute];
  205. self.cl.exType=3;
  206. [self buttonSymbolStyleReduction:sender];
  207. [self buttonSymbolStyle:sender];
  208. _curKeyToForgetPwd = [NSMutableString new];
  209. break;
  210. case 115:
  211. //加
  212. [self execute];
  213. self.cl.exType=4;
  214. [self buttonSymbolStyleReduction:sender];
  215. [self buttonSymbolStyle:sender];
  216. _curKeyToForgetPwd = [NSMutableString new];
  217. break;
  218. case 117:
  219. //小数点
  220. [self decimalPoint:self.TF Button:sender];
  221. _curKeyToForgetPwd = [NSMutableString new];
  222. break;
  223. case 118:
  224. //等
  225. [self didClickEqualbuttonFun];
  226. [self execute];
  227. self.cl.exType=0;
  228. [self buttonSymbolStyleReduction:sender];
  229. // self.TF.text=@"0";
  230. break;
  231. default:
  232. //判断清空计数
  233. if (self.emptyCount!=0) {
  234. self.TF.text=@"";
  235. self.emptyCount=0;
  236. }
  237. [self buttonSymbolStyleReduction:sender];
  238. [(UIButton *)[self.view viewWithTag:100] setTitle:@"C" forState:UIControlStateNormal];
  239. [self textFieldValueChange:self.TF Button:sender];
  240. _curKeyToForgetPwd = [NSMutableString new];
  241. break;
  242. }
  243. [self addTextFieldFormat];
  244. HLog(@"忘记密码:%@",_curKeyToForgetPwd);
  245. }
  246. #pragma mark ----样式处理----
  247. //添加点击运算符号button样式方法
  248. -(void)buttonSymbolStyle:(UIButton *)sender{
  249. [sender.layer setBorderWidth:2];
  250. }
  251. //还原运算符号button样式方法
  252. -(void)buttonSymbolStyleReduction:(UIButton *)sender{
  253. [((UIButton *)[self.view viewWithTag:103]).layer setBorderWidth:0] ;
  254. [((UIButton *)[self.view viewWithTag:107]).layer setBorderWidth:0] ;
  255. [((UIButton *)[self.view viewWithTag:111]).layer setBorderWidth:0] ;
  256. [((UIButton *)[self.view viewWithTag:115]).layer setBorderWidth:0] ;
  257. [sender.layer setBorderWidth:0];
  258. }
  259. //添加textfield格式
  260. -(void)addTextFieldFormat{
  261. NSMutableString *mutableStr=[NSMutableString stringWithString:self.TF.text];
  262. NSInteger mutableStrLength=mutableStr.length;
  263. //判断是否包含小数点 如果包含获取小数点左边的数字个数mutableStrLength
  264. if ([mutableStr containsString:@"."]) {
  265. mutableStrLength=[self getPointLeft:mutableStr];
  266. }else{
  267. mutableStrLength=[self getNumberCount:mutableStr];
  268. }
  269. for(int i=3 ; i<mutableStrLength ; i++ ){
  270. //每三个数字添加一次分隔符
  271. if (i%3==0) {
  272. //添加分隔逗号
  273. if (mutableStrLength>i) {
  274. NSInteger index=mutableStr.length-i-(mutableStr.length-mutableStrLength);
  275. NSRange range=NSMakeRange(index-1, 1);
  276. //如果上一个不是负号则添加分隔逗号
  277. if (![[mutableStr substringWithRange:range]isEqualToString:@"-"]) {
  278. //如果第一个是负号 分隔符位置+1
  279. if ([[mutableStr substringWithRange:NSMakeRange(0, 1)]isEqualToString:@"-"]) {
  280. [mutableStr insertString:@"," atIndex:index+1];
  281. }else{
  282. [mutableStr insertString:@"," atIndex:index];
  283. }
  284. }else{
  285. [mutableStr insertString:@"," atIndex:index+1];
  286. }
  287. }
  288. }
  289. }
  290. //如果textfield为空时 自动补0
  291. if ([mutableStr isEqualToString:@""]) {
  292. mutableStr=[NSMutableString stringWithString:@"0"];
  293. }
  294. self.TF.text=mutableStr;
  295. }
  296. //去除textfield格式
  297. -(void)removeTextFieldFormat{
  298. if ([self.TF.text isEqualToString:@"0"]) {
  299. self.TF.text=@"";
  300. }
  301. self.TF.text=[self.TF.text stringByReplacingOccurrencesOfString:@"," withString:@""];
  302. }
  303. //textField内容处理方法 限制输入长度 添加分隔符
  304. -(void)textFieldValueChange:(UITextField *)tf Button:(UIButton *)sender{
  305. NSString *buttonTitleStr=sender.titleLabel.text;
  306. if ([self getNumberCount:tf.text]<9) {
  307. tf.text=[tf.text stringByAppendingString:buttonTitleStr];
  308. }
  309. NSLog(@"tf.text = %@",tf.text);
  310. if(tf.text.length == 4){
  311. [self verifyPwdFun:tf.text];
  312. }
  313. // if ([tf.text isEqualToString:pwd]){
  314. // [connectDeviceManager shareInstance].isFirstInputPwdDone = YES;
  315. //
  316. // [[NSNotificationCenter defaultCenter] postNotificationName:ShowImgAndVoiceNotification object:nil];
  317. //
  318. // [self.view removeFromSuperview];
  319. // }
  320. }
  321. #pragma mark 验证密码是否正确
  322. -(void)verifyPwdFun:(NSString*)text{
  323. /*先判断本地有无设备 无设备时需要先扫码添加设备*/
  324. NSDictionary *deviceDict = [HWDataManager getObjectWithKey:Const_Have_Add_Device];
  325. if (deviceDict && [[deviceDict allKeys] containsObject:Const_Have_Add_Device_SN]){
  326. //有设备了先去做链接准备 // 80bec9c5
  327. NSString *SNStr = deviceDict[@"Const_Have_Add_Device_SN"];
  328. if(SNStr){
  329. // [[connectDeviceManager shareInstance] getThridMsgBySN:SNStr needReconnect:NO didNetEnd:^(bool didSuc) {
  330. //
  331. // if(didSuc){
  332. NSString *curPwd = nil;
  333. NSString*desPwdStr = nil;
  334. if([connectDeviceManager shareInstance].DeviceThirdIdMod.data.password
  335. && [connectDeviceManager shareInstance].DeviceThirdIdMod.data.password.length > 0){
  336. curPwd = [connectDeviceManager shareInstance].DeviceThirdIdMod.data.password;
  337. desPwdStr = [RSATool AES128Decrypt:curPwd key:AESCODEKEEYY];
  338. }
  339. else{
  340. if(deviceDict && [[deviceDict allKeys] containsObject:Const_Have_Add_Device_PWD])
  341. {
  342. desPwdStr = deviceDict[Const_Have_Add_Device_PWD];
  343. }
  344. }
  345. if ([desPwdStr isEqualToString:text]){
  346. [connectDeviceManager shareInstance].isFirstInputPwdDone = YES;
  347. [self.view removeFromSuperview];
  348. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  349. [[NSNotificationCenter defaultCenter] postNotificationName:ShowImgAndVoiceNotification object:nil];
  350. });
  351. }
  352. // }
  353. // else{
  354. //
  355. // }
  356. //
  357. // }];
  358. }
  359. }
  360. }
  361. //小数点限制方法
  362. -(void)decimalPoint:(UITextField *)tf Button:(UIButton *)sender{
  363. //判断是否已经输入小数点
  364. if (![tf.text containsString:@"."]) {
  365. tf.text=[tf.text stringByAppendingString:sender.titleLabel.text];
  366. }
  367. //判断是否直接输入小数点
  368. if([self.TF.text isEqualToString:@"."]){
  369. self.TF.text=@"0.";
  370. }
  371. }
  372. //获取小数点左边数字个数
  373. -(NSInteger)getPointLeft:(NSString *)str{
  374. NSInteger pointLeft=str.length;
  375. //判断是否包含小数点 如果包含获取小数点左边的数字个数
  376. if ([str containsString:@"."]) {
  377. NSRange range = [str rangeOfString:@"."];
  378. NSLog(@"getPointLeft=%ld",range.location);
  379. pointLeft=range.location;
  380. }
  381. //判断是否包含负号
  382. if ([str containsString:@"-"]) {
  383. pointLeft-=1;
  384. }
  385. return pointLeft;
  386. }
  387. //获取小数点右边数字个数
  388. -(NSInteger)getPointRight:(NSString *)str{
  389. NSInteger pointRight=0;
  390. //判断是否包含小数点 如果包含获取小数点右边的数字个数
  391. if ([str containsString:@"."]) {
  392. NSRange range = [str rangeOfString:@"."];
  393. NSLog(@"getPointRight=%ld",str.length- range.location);
  394. pointRight=str.length- range.location;
  395. }
  396. return pointRight;
  397. }
  398. //获取纯数字个数
  399. -(NSInteger)getNumberCount:(NSString *)str{
  400. NSInteger numberCount=str.length;
  401. //判断是否包含小数点
  402. if ([str containsString:@"."]) {
  403. numberCount-=1;
  404. }
  405. //判断是否包含负号
  406. if ([str containsString:@"-"]) {
  407. numberCount-=1;
  408. }
  409. //判断是否包含分隔逗号
  410. if ([str containsString:@","]) {
  411. if ([self getPointLeft:str]<5) {
  412. numberCount-=1;
  413. }else{
  414. numberCount-=2;
  415. }
  416. }
  417. return numberCount;
  418. }
  419. //UIColor 转UIImage
  420. - (UIImage*) createImageWithColor: (UIColor*) color{
  421. CGRect rect=CGRectMake(0.0f, 0.0f, 1.0f, 1.0f);
  422. UIGraphicsBeginImageContext(rect.size);
  423. CGContextRef context = UIGraphicsGetCurrentContext();
  424. CGContextSetFillColorWithColor(context, [color CGColor]);
  425. CGContextFillRect(context, rect);
  426. UIImage *theImage = UIGraphicsGetImageFromCurrentImageContext();
  427. UIGraphicsEndImageContext();
  428. return theImage;
  429. }
  430. - (void)didReceiveMemoryWarning {
  431. [super didReceiveMemoryWarning];
  432. // Dispose of any resources that can be recreated.
  433. }
  434. #pragma mark ----运算----
  435. //正负数转换
  436. -(void)getPlusMinus:(NSString *)number{
  437. self.TF.text=[self.cl getPlusMinus:self.TF.text];
  438. [self textFieldLastValue];
  439. }
  440. //ios计算器bug
  441. //2 * 9 ÷ 目前等于18 转换正负数会变为-0
  442. //计算百分比
  443. -(void)getPercentage:(NSString *)number{
  444. //记录特殊情况--忘记密码输入
  445. if(!number || number.intValue == 0){
  446. if(!_curKeyToForgetPwd || _curKeyToForgetPwd.length == 0){
  447. _curKeyToForgetPwd = [[NSMutableString alloc] initWithFormat:@"%@",@"%"];
  448. //HLog(@"11:%@",_curKeyToForgetPwd);
  449. }
  450. else if(_curKeyToForgetPwd.length == 3){
  451. [_curKeyToForgetPwd appendString:@"%"];
  452. [self checkOrderToForgetPwdFun];
  453. }
  454. }
  455. number=[NSString stringWithFormat:@"%f",[number doubleValue]/100];
  456. //去除floa转换后后面多余的0
  457. self.TF.text = [NSString stringFloatHandle:number];
  458. [self textFieldLastValue];
  459. }
  460. //ios计算器bug
  461. //5 * 点击% 变成0.05 再点6 等于30 而不是0.3
  462. //判断textfield上的内容是否为上一次的运算结果 并进行赋值操作 以保证连续运算时执行以上两种操作后的结果能够正确参与运算
  463. -(void)textFieldLastValue{
  464. //如果number1和result都不为空 number2为空 并且清空计数为1(说明刚刚点击过运算符号button) 说明当前textfield上的内容为上一次的运算结果
  465. if (self.cl.number1 != nil) {
  466. if (self.cl.result != nil) {
  467. if (self.cl.number2==nil) {
  468. if (self.emptyCount==1) {
  469. self.cl.number1=self.TF.text;//将转换后的值赋给number1,以便下次运算使用
  470. }
  471. }
  472. }
  473. }
  474. }
  475. //四则运算
  476. -(void)execute{
  477. if(self.emptyCount==0){
  478. if(self.cl.number1 ==nil){
  479. self.cl.number1=self.TF.text;
  480. }else{
  481. self.cl.number2=self.TF.text;
  482. }
  483. //如果number1和number2都不为空 进行计算
  484. if (self.cl.number2 != nil && self.cl.number1 != nil) {
  485. //判断除数是否为0
  486. if([self.cl.number2 isEqualToString:@""]&&self.cl.exType==1){
  487. self.TF.text=@"错误";
  488. }else{
  489. self.TF.text=[self.cl Execute];
  490. }
  491. }
  492. //清空计数
  493. self.emptyCount=1;
  494. }
  495. }
  496. #pragma mark 按=号
  497. - (void)didClickEqualbuttonFun
  498. {
  499. //记录特殊情况--忘记密码输入
  500. //HLog(@"22:%@",self.TF.text)
  501. if(!self.TF.text
  502. || self.TF.text.length == 0
  503. || [self.TF.text isEqualToString:@"0"]){
  504. if(_curKeyToForgetPwd
  505. && _curKeyToForgetPwd.length >=1
  506. && [keyToForgetPwd rangeOfString:_curKeyToForgetPwd].location != NSNotFound
  507. ){
  508. [_curKeyToForgetPwd appendString:@"="];
  509. }
  510. }
  511. }
  512. #pragma mark 验证是否为忘记密码指令
  513. - (void)checkOrderToForgetPwdFun
  514. {
  515. if([_curKeyToForgetPwd isEqualToString:keyToForgetPwd]){
  516. [[NSNotificationCenter defaultCenter] postNotificationName:forgetPwdNotification object:nil];
  517. }
  518. _curKeyToForgetPwd = [NSMutableString new];
  519. }
  520. @end