搜索

首页  >  问答  >  正文

ios - 点击完添加任务,再点取消控件失去响应问题

我点击完添加任务,然后再按返回键,想要收回键盘,改变约束,发现卡住了,当然如果数据少的话,不存在这个问题
图片和代码如下


UIButton *addCard = UIButton.new;

            [footer addSubview:addCard];
                   [self.arrAddCards addObject:addCard];
    
                    [addCard makeConstraints:^(MASConstraintMaker *make) {

                        make.top.equalTo(0);
                        make.bottom.equalTo(0);
                        make.right.equalTo(0);
                        make.left.equalTo(0);
                        
                    }];
                    [addCard setTitle:@"添加任务" forState:UIControlStateNormal];
                    [addCard setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
                    [addCard setTitleColor:[UIColor lightGrayColor] forState:UIControlStateHighlighted];
                    addCard.titleLabel.font = [UIFont systemFontOfSize:15];
                    addCard.backgroundColor = [UIColor clearColor];
                    self.addCards = addCard;
                    // [addCard addTarget:self action:@selector(addCard:) forControlEvents:UIControlEventTouchUpInside];
                    //使用ReactiveCocoa处理点击事件,相当于上面的addTarget:方法
                    //addCard点击事件
                    [[addCard rac_signalForControlEvents:UIControlEventTouchUpInside] subscribeNext:^(id x) {
                         NSLog(@"%ld",(unsigned long)self.unNetArr.count);
                      
                          self.yesOrNo = NO;
                          //隐藏addCard
                          addCard.alpha = 0;
                          //输入框
                          UITextView *textView = ({
                              UITextView *view = [UITextView new];
                              [footer addSubview:view];
                              [view makeConstraints:^(MASConstraintMaker *make) {
                                  make.left.equalTo(10);
                                  make.top.equalTo(3);
                                  make.right.equalTo(-10);
                                  make.bottom.equalTo(-44+2);
                              }];
                              //因为footer变大,所以改变tableView的contentInset
                              listTableView.contentInset = UIEdgeInsetsMake(46, 0, 88, 0);
                              
                              view.font = [UIFont systemFontOfSize:15];
                              
                              //立即刷新视图
                              [self layoutIfNeeded];
                              
                              view;
                          });
                          self.textView = textView;
                          
                          //初始化add按钮
                          UIButton *add = ({
                              
                              UIButton *view = [UIButton new];
                              view.contentHorizontalAlignment=UIControlContentHorizontalAlignmentCenter;
                              [view setTitle:NSLocalizedString(@"add", nil) forState:UIControlStateNormal];
                              [view setTitleColor:Global_trelloBlue forState:UIControlStateNormal];
                              [view setTitleColor:[UIColor lightGrayColor] forState:UIControlStateHighlighted];
                              [view setTitleEdgeInsets:UIEdgeInsetsMake(0, -40, 0, -80)];
                              [view.titleLabel setFont:[UIFont fontWithName:@"Arial-Bold" size:18]];
                              view.titleLabel.font = [UIFont systemFontOfSize:15];
                              [footer addSubview:view];
                              [view makeConstraints:^(MASConstraintMaker *make) {
                                  make.right.equalTo(0);
                                  make.bottom.equalTo(-1);
                                  make.width.equalTo(120);
                              }];
                              
                              [view sizeToFit];
                              //初始化后隐藏(为了动画效果)
                              view.alpha = 0;
                              //立即刷新
                              [self layoutIfNeeded];
                              
                              //add点击事件,创建新的tast
                              [[view rac_signalForControlEvents:UIControlEventTouchUpInside] subscribeNext:^(id x) {
                                  
                                  //textView判空
                                  if (![textView.text isEqualToString:@""]) {
                                      self.yesOrNo = NO;
                                      AddTaskApi *api = AddTaskApi.new;
                                      //如果在没有task的列添加新的task,t_sort传0
                                      api.t_sort = @(0);
                                      //都上传0
                                      api.t_taskContent = textView.text;
                                      api.t_projectId = @(_project_id.integerValue);
                                      //当前列的id
                                      api.t_panel_id = @(listTableView.model.id.integerValue);
                                      NSLog(@"<><>%@",_project_id);
                                      //判断是否有网
                                      [GLobalRealReachability reachabilityWithBlock:^(ReachabilityStatus status) {
                                          switch (status)
                                          {
                                              case RealStatusNotReachable:
                                              {
                                                  NewTasklistModel *model = [[NewTasklistModel alloc]init];
                                                  model.unloading = YES;
                                                  model.t_taskContent = textView.text;
                                                  textView.text = nil;
                                                  model.t_sort = @"0";
                                                  model.t_id = [_project_id integerValue];
                                                  model.t_panel_id = listTableView.model.id;
                                                  model.page = idx;
                                                  
                                                  [listTableView.model.task addObject:model];
                                                  [self.unNetArr addObject:model];
                                                  NSLog(@"%ld",(unsigned long)self.unNetArr.count);
                                                  //插入行
                                                  [listTableView insertRow:(listTableView.model.task.count-1)inSection:0 withRowAnimation:
                                                   UITableViewRowAnimationBottom];
                                                  
                                                  //计算rowHeight
                                                  CGFloat rowHeight = [self tableView:listTableView heightForRowAtIndexPath:[NSIndexPath indexPathForRow:listTableView.model.task.count-1 inSection:0]];
                                                  //根据当前列高度和rowHeight决定列高度是否增加
                                                  //updateConstraints:方法更新autolayout
                                                  [listView updateConstraints:^(MASConstraintMaker *make) {
                                                      //增加新的rowHeight后list超出允许最大高度,之前不满最大高度
                                                      if (listTableView.cellTotalHeight > (kTotalCellMaxHeight+NavAndStatusBarHeight-_keyboardHeight-44) && (listTableView.cellTotalHeight-rowHeight) < (kTotalCellMaxHeight+NavAndStatusBarHeight-_keyboardHeight-44)) {
                                                          make.height.equalTo(listView.yyHeight+((kTotalCellMaxHeight+NavAndStatusBarHeight-_keyboardHeight-44)-(listTableView.cellTotalHeight-rowHeight)));
                                                      }
                                                      //增加新的rowHeight后list没有超过允许最大高度
                                                      if (listTableView.cellTotalHeight <= (kTotalCellMaxHeight+NavAndStatusBarHeight-_keyboardHeight-44)) {
                                                          make.height.equalTo(listView.yyHeight+rowHeight);
                                                      }
                                                  }];
                                                  //tableView滚动到最底部,显示新添加行
                                                  [listTableView scrollToRow:listTableView.model.task.count-1 inSection:0 atScrollPosition:UITableViewScrollPositionBottom animated:NO];
                                                  //autolayout动画
                                                  [self layoutIfNeeded];
                                                  //                                               [listTableView reloadRow:listTableView.model.task.count-1 inSection:0 withRowAnimation:UITableViewRowAnimationBottom];
                                                  
                                                  
                                                  //改变原列的标题数量
                                                  UITextField *sourceListTableHeaderTF=(UITextField *)[self viewWithTag:[listTableView.model.id integerValue]];
                                                  sourceListTableHeaderTF.text=[NSString stringWithFormat:@"%@ %ld",listTableView.model.name,(unsigned long)listTableView.model.task.count];
                                                  break;
                                              }
                                              case RealStatusUnknown:
                                              {
                                                  NewTasklistModel *model = [[NewTasklistModel alloc]init];
                                                  model.unloading = YES;
                                                  model.t_taskContent = textView.text;
                                                  textView.text = nil;
                                                  model.t_sort = @"0";
                                                  model.t_id = [_project_id integerValue];
                                                  model.t_panel_id = listTableView.model.id;
                                                  model.page = idx;
                                                  
                                                  [listTableView.model.task addObject:model];
                                                  [self.unNetArr addObject:model];
                                                  
                                                  //插入行
                                                  [listTableView insertRow:(listTableView.model.task.count-1)inSection:0 withRowAnimation:
                                                   UITableViewRowAnimationBottom];
                                                  
                                                  //计算rowHeight
                                                  CGFloat rowHeight = [self tableView:listTableView heightForRowAtIndexPath:[NSIndexPath indexPathForRow:listTableView.model.task.count-1 inSection:0]];
                                                  //根据当前列高度和rowHeight决定列高度是否增加
                                                  //updateConstraints:方法更新autolayout
                                                  [listView updateConstraints:^(MASConstraintMaker *make) {
                                                      //增加新的rowHeight后list超出允许最大高度,之前不满最大高度
                                                      if (listTableView.cellTotalHeight > (kTotalCellMaxHeight+NavAndStatusBarHeight-_keyboardHeight-44) && (listTableView.cellTotalHeight-rowHeight) < (kTotalCellMaxHeight+NavAndStatusBarHeight-_keyboardHeight-44)) {
                                                          make.height.equalTo(listView.yyHeight+((kTotalCellMaxHeight+NavAndStatusBarHeight-_keyboardHeight-44)-(listTableView.cellTotalHeight-rowHeight)));
                                                      }
                                                      //增加新的rowHeight后list没有超过允许最大高度
                                                      if (listTableView.cellTotalHeight <= (kTotalCellMaxHeight+NavAndStatusBarHeight-_keyboardHeight-44)) {
                                                          make.height.equalTo(listView.yyHeight+rowHeight);
                                                      }
                                                  }];
                                                  //tableView滚动到最底部,显示新添加行
                                                  [listTableView scrollToRow:listTableView.model.task.count-1 inSection:0 atScrollPosition:UITableViewScrollPositionBottom animated:NO];
                                                  //autolayout动画
                                                  [self layoutIfNeeded];
                                                  
                                                  
                                                  
                                                  //改变原列的标题数量
                                                  UITextField *sourceListTableHeaderTF=(UITextField *)[self viewWithTag:[listTableView.model.id integerValue]];
                                                  sourceListTableHeaderTF.text=[NSString stringWithFormat:@"%@ %ld",listTableView.model.name,(unsigned long)listTableView.model.task.count];
                                                  break;
                                              }
                                                  
                                                  
                                              default:
                                                  //发起请求
                                                  [api startWithCompletionBlockWithSuccess:^(YTKBaseRequest *request) {
                                                      SLog(@"<><>>>%@",request);
                                                      NewTasklistModel *model = request.responseModel;
                                                      model.unloading = NO;
                                                      
                                                      //存在即失败(接口定义,只在失败时才返回status值)
                                                      if (model.status) {
                                                          
                                                      }
                                                      else { //添加成功
                                                          textView.text = nil;
                                                          //更新数据源
                                                          [listTableView.model.task addObject:model];
                                                          //插入行
                                                          [listTableView insertRow:(listTableView.model.task.count-1)inSection:0 withRowAnimation:
                                                           UITableViewRowAnimationBottom];
                                                          //计算rowHeight
                                                          CGFloat rowHeight = [self tableView:listTableView heightForRowAtIndexPath:[NSIndexPath indexPathForRow:listTableView.model.task.count-1 inSection:0]];
                                                          
                                                          
                                                          //根据当前列高度和rowHeight决定列高度是否增加
                                                          //updateConstraints:方法更新autolayout
                                                          
                                                          [listView updateConstraints:^(MASConstraintMaker *make) {
                                                              //增加新的rowHeight后list超出允许最大高度,之前不满最大高度
                                                              if (listTableView.cellTotalHeight > (kTotalCellMaxHeight+NavAndStatusBarHeight-_keyboardHeight-44) && (listTableView.cellTotalHeight-rowHeight) < (kTotalCellMaxHeight+NavAndStatusBarHeight-_keyboardHeight-44)) {
                                                                  make.height.equalTo(listView.yyHeight+((kTotalCellMaxHeight+NavAndStatusBarHeight-_keyboardHeight-44)-(listTableView.cellTotalHeight-rowHeight)));
                                                              }
                                                              
                                                              //增加新的rowHeight后list没有超过允许最大高度
                                                              if (listTableView.cellTotalHeight <= (kTotalCellMaxHeight+NavAndStatusBarHeight-_keyboardHeight-44)) {
                                                                  make.height.equalTo(listView.yyHeight+rowHeight);
                                                              }
                                                          }];
                                                          //tableView滚动到最底部,显示新添加行
                                                          [listTableView scrollToRow:listTableView.model.task.count-1 inSection:0 atScrollPosition:UITableViewScrollPositionBottom animated:NO];
                                                          [self layoutIfNeeded];
                                                          //autolayout动画
                                                          
                                                          
                                                          //改变原列的标题数量
                                                          UITextField *sourceListTableHeaderTF=(UITextField *)[self viewWithTag:[listTableView.model.id integerValue]];
                                                          sourceListTableHeaderTF.text=[NSString stringWithFormat:@"%@ %ld",listTableView.model.name,(unsigned long)listTableView.model.task.count];
                                                          
                                                      }
                                                  } failure:^(YTKBaseRequest *request) {
                                                      
                                                  }];
                                                  break;
                                          }
                                      }];
                                      
                                      
                                      
                                      
                                      
                                  }else{
                                      self.yesOrNo = YES;
                                      
                                      [footer updateConstraints:^(MASConstraintMaker *make) {
                                          make.height.equalTo(44);
                                      }];
                                      //list减去footer增加的高度(在这里做是为了动效)
                                      [listView updateConstraints:^(MASConstraintMaker *make) {
                                          make.height.equalTo(listView.yyHeight-44);
                                      }];
                                      //tableView的contentInset还原
                                      listTableView.contentInset = UIEdgeInsetsMake(46, 0, 44, 0);
                                      //隐藏textView
                                      textView.alpha = 0;
                                      
                                      [UIView animateWithDuration:0.25 animations:^{
                                          //cancel隐藏
                                          view.alpha = 0;
                                          
                                          //add隐藏
                                          self.cancel.alpha = 0;
                                          //addCard显示
                                          addCard.alpha = 1;
                                          [self.viewController.navigationController setNavigationBarHidden:NO animated:YES];
                                          [self layoutIfNeeded];
                                      }];
                                      [textView resignFirstResponder];
                                      
                                  }
                              }];
                              view;
                          });
                          self.addView = add;
                          //初始化cancel按钮
                          UIView *cancel = ({
                              UIButton *view = [UIButton new];
                              view.contentHorizontalAlignment=UIControlContentHorizontalAlignmentCenter;
                              [view setTitle:NSLocalizedString(@"cancel", nil) forState:UIControlStateNormal];
                              [view setTitleColor:Global_trelloBlue forState:UIControlStateNormal];
                              [view.titleLabel setFont:[UIFont fontWithName:@"Arial-Bold" size:18]];
                              [view setTitleColor:[UIColor lightGrayColor] forState:UIControlStateHighlighted];
                              [view setTitleEdgeInsets:UIEdgeInsetsMake(0, -80, 0, -40)];
                              view.titleLabel.font = [UIFont systemFontOfSize:15];
                              [footer addSubview:view];
                              [view makeConstraints:^(MASConstraintMaker *make) {
                                  make.left.equalTo(0);
                                  make.bottom.equalTo(-1);
                                  make.width.equalTo(120);
                              }];
                              [view sizeToFit];
                              view.alpha = 0;
                              [self layoutIfNeeded];
                              //cancel点击事件
                              @weakify(self, view, textView, footer, listView, add, addCard)
                              [[view rac_signalForControlEvents:UIControlEventTouchUpInside] subscribeNext:^(id x)
                               {
                                   @strongify(self, view, textView, footer, listView, add, addCard)
                                     //footer高度还原
                                     self.yesOrNo = YES;
                                     [textView resignFirstResponder];
                                     // list减去footer增加的高度(在这里做是为了动效)
                                     [footer updateConstraints:^(MASConstraintMaker *make) {
                                         make.height.equalTo(44);
                                     }];
                                     [listView updateConstraints:^(MASConstraintMaker *make) {
                                         make.height.equalTo(listView.yyHeight);
                                     }];
                                   //  tableView的contentInset还原
                                     listTableView.contentInset = UIEdgeInsetsMake(46, 0, 44, 0);
                                   // 隐藏textView
                                     textView.alpha = 0;
                                     [UIView animateWithDuration:0.5 animations:^{
                                         //cancel隐藏
                                         view.alpha = 0;
                                         //add隐藏
                                         add.alpha = 0;
                                         //addCard显示
                                         addCard.alpha = 1;
                                         [self.viewController.navigationController setNavigationBarHidden:NO animated:NO];
                                         [self layoutIfNeeded];
                                     }];
                                }];
                              view;
                          });
                          self.cancel = cancel;
                          // addCard点击后动效
                          [footer updateConstraints:^(MASConstraintMaker *make) {
                              make.height.equalTo(44+44);
                          }];
                          [textView updateConstraints:^(MASConstraintMaker *make) {
                              make.top.equalTo(2);
                          }];
                          [listView updateConstraints:^(MASConstraintMaker *make) {
                              make.height.equalTo(listView.yyHeight+44);
                          }];
                          self.contentSize = CGSizeMake(self.contentSize.width, 244);
                          [UIView animateWithDuration:0.25 animations:^{
                              [self.viewController.navigationController setNavigationBarHidden:YES animated:YES];
                              add.alpha = 1;
                              cancel.alpha = 1;
                              [self layoutIfNeeded];
                          }];
                          //弹出键盘
                          [textView becomeFirstResponder];
                          //tableView滚动到最底部,显示新添加行
                          //                            [listTableView scrollToBottom];
                          listTableView.bounces = NO;
                          if (listTableView.model.task.count>1) {
                              
                              [listTableView scrollToRow:listTableView.model.task.count-1 inSection:0 atScrollPosition:UITableViewScrollPositionBottom animated:YES];
                          }
                    
                    }];
迷茫迷茫2771 天前471

全部回复(0)我来回复

暂无回复
  • 取消回复