我点击完添加任务,然后再按返回键,想要收回键盘,改变约束,发现卡住了,当然如果数据少的话,不存在这个问题
图片和代码如下
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 indexP
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…