请教一个聊天布局中遇到的问题

a2639966489 2018-04-24 01:15:29
源代码已上传,在聊天布局中我运行这个程序以后第一次的高度无法精确计划,只能下拉刷新重新加载以后高度才正确,请问是什么原因呢。代码如下


- (void)settingShowTextButton:(UIButton *)showTextButton showIconView:(UIImageView *)showIconView hideTextButton:(UIButton *)hideTextButton hideIconView:(UIImageView *)hideIconView
{
hideTextButton.hidden = YES;
hideIconView.hidden = YES;

showTextButton.hidden = NO;
showIconView.hidden = NO;

// 设置按钮的文字
[showTextButton setTitle:self.message.text forState:UIControlStateNormal];

// 强制更新
[showTextButton layoutIfNeeded];

// 设置按钮的高度就是titleLabel的高度
[showTextButton updateConstraints:^(MASConstraintMaker *make) {
CGFloat buttonH = showTextButton.titleLabel.frame.size.height;
make.height.equalTo(buttonH);
}];

// 强制更新
[showTextButton layoutIfNeeded];

// 计算当前cell的高度
CGFloat buttonMaxY = CGRectGetMaxY(showTextButton.frame);
CGFloat iconMaxY = CGRectGetMaxY(showIconView.frame);
self.message.cellHeight = MAX(buttonMaxY, iconMaxY) + 10;
}


...全文
926 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
Miracle_Tan 2018-06-23
  • 打赏
  • 举报
回复
你调用下layoutsubview方法设置下,不要再这个方法中掉布局的东西试试

29,027

社区成员

发帖
与我相关
我的任务
社区描述
主要讨论与iOS相关的软件和技术
社区管理员
  • iOS
  • 大熊猫侯佩
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧