我有一个UITableView
与3个单元格,最终将作为仪表板。我正在尝试使用KDCircularProgress
来配置带有圆形进度视图的顶部单元格 - 我有一个UIView
,我用约束定位,然后以编程方式添加循环进度对象。更新方向变化UITableViewCell子视图约束
但是,当我将设备旋转到风景时,进度视图会发生变化(请参阅第一幅图像)。我尝试过setNeedsLayout()
,layoutSubviews
和layoutIfNeeded()
的各种组合,但没有运气。
我也尝试reloadData()
在willAnimateRotation(to toInterfaceOrientation: UIInterfaceOrientation, duration: TimeInterval)
,这让我略微进一步,因为视图正确调整大小(请参阅第二张图片),但它创建了重复。从cellForRowAt
提取方法如下:
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
switch indexPath.row {
case 0:
let topCell = tableView.dequeueReusableCell(withIdentifier: "topCell", for: indexPath) as! DashboardTopTableViewCell
//Progress config
topCell.progressBar = KDCircularProgress(frame: CGRect(origin: CGPoint.zero, size: CGSize(width: topCell.circularProgressContainer.frame.width, height: topCell.circularProgressContainer.frame.height)))
let colorForProgress: UIColor = UIColor(red: 69.0/255.0, green: 110.0/255.0, blue: 178.0/255.0, alpha: 0.8)
topCell.progressBar?.progressColors = [colorForProgress]
let progressAsAngle = ((percentageComplete/100)*360)
topCell.progressBar?.animate(toAngle: progressAsAngle, duration: 2.0, completion: nil)
topCell.circularProgressContainer.addSubview(topCell.progressBar!)
return topCell
所以我有点卡住了 - 有什么建议吗?
在cellForRow使用addSubview
好的,理解。当你说'在任何地方查看'添加视图时,你有什么想法? – Tom
我想你会将DashboardTopTableViewCell作为Storyboard或XIB中的原型单元格,您可以在其中添加。 –
对不起,应该提到KDCircularProgress没有Storyboard对象,因此我以编程方式创建它。 – Tom