0
我的滚动视图具有包含大量组件的内容视图,并且组件在单击时呈现动画效果。有一个问题,内容视图不会正确更改大小。有没有人有任何想法如何解决这个问题?滚动后面的contnent视图的大小。这里是描述代码,我在做什么:内容将视图调整为父滚动视图
func updateDropDownList(tableView: UITableView, height: CGFloat, state: CGFloat) {
let rowHeight = tableView.rowHeight
UIView.animate(withDuration: 0.3, animations: {
var frame = CGRect(x: tableView.frame.origin.x, y: tableView.frame.origin.y, width: tableView.frame.width, height: height)
tableView.frame = frame
if state == -1 {
frame = CGRect(x: tableView.frame.origin.x, y: tableView.frame.origin.y, width: tableView.frame.width, height: CGFloat(tableView.numberOfRows(inSection: 0)) * rowHeight)
}
self.updatePositions(tableView: tableView, frame: frame, state: state, rowHeight: rowHeight)
})
}
状态:
- 状态= 1个//调整表视图
- 状态= -1 //回oryginal大小
和方法,其允许我改变各成分的位置:
func updatePositions(tableView: UITableView, frame: CGRect, state: CGFloat, rowHeight: CGFloat) {
switch tableView {
case facilitiesTableView:
statusLabel.frame.origin.y += state * (frame.height - rowHeight)
statusTableView.frame.origin.y += state * (frame.height - rowHeight)
serviceTableView.frame.origin.y += state * (frame.height - rowHeight)
vehiclesCollection.frame.origin.y += state * (frame.height - rowHeight)
colorsCollection.frame.origin.y += state * (frame.height - rowHeight)
scrollView.contentSize.height += state * colorsCollection.frame.height
// contentView.frame.size = CGSize(width: contentView.frame.size.width, height: scrollView.contentSize.height)
case statusTableView:
serviceTableView.frame.origin.y += state * (frame.height - rowHeight)
vehiclesCollection.frame.origin.y += state * (frame.height - rowHeight)
colorsCollection.frame.origin.y += state * (frame.height - rowHeight)
scrollView.contentSize.height += state * colorsCollection.frame.height
case serviceTableView:
vehiclesCollection.frame.origin.y += state * (frame.height - rowHeight)
colorsCollection.frame.origin.y += state * (frame.height - rowHeight)
scrollView.contentSize.height += state * colorsCollection.frame.height
default:
break
}
}
有一条注释行调整了内容视图的大小,但是当我调用它时,会使屏幕变乱,点击的表格不会调整视图的大小,因为如果我没有错误,这些组件会重新绘制它们。
没有调整大小的视图来适应滚动视图我不能点击最低的组件,因为它们超出了内容视图的范围。
非常感谢!
如果我在动画之前添加它,它是不会帮助,如果我把它放在它不会让我点击甚至表视图 - 它不会拉伸 – yerpy
您是否使用任何布局约束? –
我是。像顶部,底部,前后滚动视图一样,每个视图都是0,并且使用滚动视图的超视图等同高度和宽度。 – yerpy