【发布时间】:2017-10-12 01:19:14
【问题描述】:
我有一个 UILabel 配置为根据文本长度自动调整多行的大小。标签位于动态调整大小的 UITableViewCell 中,所有大小都有约束。
代码将 UILabel 原点向右移动,从而缩小了 UILabel 宽度。
标签正确调整了文本的大小和换行。在将原点定位回其原始位置的过程中,UILabel 的高度扩展了 3 行。但只需要 2 行文本。
之所以高度扩大为3行,是因为在view动画回原点的过程中,文字扩大为3行,缩小为2行。
是否有可以使单元格正确调整大小的调用或设置?或者 2 有没有办法让单元格在原点更改时不调整大小。尤其。是否可以在宽度缩小和扩大时暂时禁用 UILabel 多行选项?
这里是显示行为的屏幕截图。
图(1)UITableViewCell改变原点前label的位置。
图(2)UILabel的原点向右移动,减少了标签的宽度。请注意,第二行有 2 行,标签边框紧紧地包裹着文本。
图(3) Origin返回第一张图片的位置。请注意,第二行的 UIlabel 松散地拥抱文本,并没有恢复到原来的高度。
@IBAction func editTable(_ sender: UIBarButtonItem) {
if isEditingDynamic {
let animate = UIViewPropertyAnimator(duration: 0.4, curve: .easeIn) {
for cell in self.tableView.visibleCells as! [CellResize] {
cell.lblDescription.frame.origin.x = 16
}
self.tableView.beginUpdates()
self.tableView.endUpdates()
}
animate.addCompletion(){
(position:UIViewAnimatingPosition) in
for cell in self.tableView.visibleCells as! [CellResize] {
cell.leadingContraint.constant = 0
}
self.tableView.beginUpdates()
self.tableView.endUpdates()
}
animate.startAnimation()
isEditingDynamic = false
} else {
let animate = UIViewPropertyAnimator(duration: 0.4, curve: .easeIn) {
for cell in self.tableView.visibleCells as! [CellResize] {
cell.lblDescription.frame.origin.x = 60
}
self.tableView.beginUpdates()
self.tableView.endUpdates()
}
animate.addCompletion(){
(position:UIViewAnimatingPosition) in
for cell in self.tableView.visibleCells as! [CellResize] {
cell.leadingContraint.constant = 54
}
self.tableView.beginUpdates()
self.tableView.endUpdates()
}
animate.startAnimation()
isEditingDynamic = true
}
}
【问题讨论】:
标签: ios uitableview uikit uilabel