看起来没有错。
UIView.animate(withDuration: 0.2, animations: {
tableView.frame = CGRect.init(x: 0, y: 40, width: screenWidth, height: (CGFloat(arr.count)*40.0 + 20.0) > screenHeight - kNaviHeight - 40 ?screenHeight - kNaviHeight - 40:(CGFloat(arr.count)*40.0) )
})
但是报错
The compiler is unable to type-check this expression in reasonable time; try breaking up the expression into distinct sub-expressions
原来。。swift5禁止这种一行代码搞定一切的骚操作。。因为嵌套的层数太多了
所以修改下
let animHeight = (CGFloat(arr.count)*40.0 + 20.0) > screenHeight - kNaviHeight - 40 ?screenHeight - kNaviHeight - 40:(CGFloat(arr.count)*40.0)
UIView.animate(withDuration: 0.2, animations: {
tableView.frame = CGRect.init(x: 0, y: 40, width: screenWidth, height:animHeight )
})
这样就可以了