问题描述
private lazy var table: UITableView = {
let table = UITableView(frame: .zero,style: .plain)
table.backgroundColor = .clear
table.separatorStyle = .none
table.dataSource = self.dataProvider
table.delegate = self.dataProvider
table.rowHeight = UITableView.automaticDimension
table.autoresizesSubviews = true
table.estimatedRowHeight = CreateContentLayout.cellHeight
table.register(CreateContentTextCell.classForCoder(),forCellReuseIdentifier: CreateContentTextCell.self.nameOfClass())
table.register(CCOutlinedTextAreaCell.classForCoder(),forCellReuseIdentifier: CCOutlinedTextAreaCell.self.nameOfClass())
table.register(CreateContentButtonCell.classForCoder(),forCellReuseIdentifier: CreateContentButtonCell.self.nameOfClass())
table.register(CreateContentPhotoCell.classForCoder(),forCellReuseIdentifier: CreateContentPhotoCell.self.nameOfClass())
table.register(CreateContentLableCell.classForCoder(),forCellReuseIdentifier: CreateContentLableCell.self.nameOfClass())
table.register(CreatContetnAttachmentsCell.classForCoder(),forCellReuseIdentifier: CreatContetnAttachmentsCell.self.nameOfClass())
table.contentInset = .zero
table.showsverticalScrollIndicator = false
table.keyboarddismissMode = .onDrag
table.tableFooterView = UIView(frame: .zero)
return table
}()
用于输入文本的单元格包含一个 UITextView。输入文本时,UITextView 和 UITableViewCell 会增加高度,一切正常。
private lazy var textField: MDCOutlinedTextArea = {
let field = MDCOutlinedTextArea()
let title: String
field.minimumNumberOfVisibleRows = 1
field.maximumNumberOfVisibleRows = .infinity
field.textView.font = CreateContentLayout.lableAboutFont
field.setoutlineColor(Color.gray,for: .normal)
field.setoutlineColor(Color.blueGray,for: .editing)
field.setTextColor(.black,for: .normal)
field.setTextColor(.black,for: .editing)
field.setFloatingLabel(Color.blueGray,for: .normal)
field.setFloatingLabel(Color.blueGray,for: .editing)
switch self.data {
case let .subject(_,value,error),let .text(_,let .phone(value,error)/*,let .region(value,error)*/,let .recipeInfo(value,let .ingredients(value,let .email(value,let .communications(value,error):
field.textView.backgroundColor = (value.isEmpty ? .clear : .white)
field.textView.text = value
default:
break
}
field.textView.delegate = self
return field
}()
func textViewDidChange(_ textView: UITextView) {
let size = textView.bounds.size
let newSize = textView.sizeThatFits(CGSize(width: size.width,height: CGFloat.greatestFiniteMagnitude))
let newHeight = (textField.sizeThatFits(CGSize(width: size.width,height: CGFloat.greatestFiniteMagnitude))).height
if size.height != newSize.height {
UIView.setAnimationsEnabled(false)
tableView?.beginUpdates()
self.textField.snp.updateConstraints {
$0.height.equalTo(newHeight)
}
tableView?.endUpdates()
UIView.setAnimationsEnabled(true)
}
self.scrollToRect(textView)
}
func setupUI() {
self.contentView.addSubview(textField)
self.textField.snp.makeConstraints {
$0.left.equalTo(BaseLayout.viewHorizontalPadding)
$0.right.equalTo(BaseLayout.viewHorizontalPadding.negated)
$0.top.equalTo(BaseLayout.viewHorizontalPadding)
$0.bottom.equalTo(BaseLayout.viewHorizontalPadding.negated).priority(.low)
}
NotificationCenter.default.addobserver(
self,selector: #selector(textDidChange(_:)),name: UITextView.textDidChangeNotification,object: self.textField.textView
)
self.layoutIfNeeded()
let newSize = self.textField.sizeThatFits(CGSize(
width: UIScreen.main.bounds.width - BaseLayout.viewHorizontalPadding * 2,height: CGFloat.greatestFiniteMagnitude
))
self.textField.snp.makeConstraints {
$0.height.equalTo(newSize.height)
}
但是,当我添加图像并且 UITableView 刷新单元格时,下面会出现一个额外的区域。
更多视频
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)