【问题标题】:Why UIImageView doesn't display rounded until scrolling?为什么 UIImageView 在滚动之前不显示四舍五入?
【发布时间】:2017-08-03 15:06:30
【问题描述】:

我的UIImageView 在滚动或重新加载集合视图时不会显示为圆形 (collectionView.reloadData())。

看起来是这样的:

  • 不四舍五入

  • 四舍五入

该单元格具有多个图像视图,并且所有这些视图都被限制为使用facesContainer UIView 约束。

我试图在collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) 内部实现这段代码:

cell.facesContainer.layer.cornerRadius = (cell.facesContainer.layer.frame.width/2)
cell.facesGroupImageView.layer.cornerRadius = (cell.facesGroupImageView.layer.frame.width/2)
cell.facesGroupImageView.layer.masksToBounds = true
cell.facesGroupImageView.layer.borderColor = UIColor.black.cgColor
cell.facesGroupImageView.layer.borderWidth = 0.5

另外,我尝试在自定义单元类中,awakeFromNib() 方法中添加上面的代码 sn-p,但它不起作用。

为什么它不起作用?如何解决?

【问题讨论】:

标签: ios swift uicollectionview uicollectionviewcell cornerradius


【解决方案1】:

我认为你应该把你的代码放在这个里面:

DispatchQueue.main.async {
   // your view configurations
}

【讨论】:

    【解决方案2】:

    在 viewWillLayoutSubviews 中设置半径即可解决问题。

    override func viewWillLayoutSubviews() { super.viewWillLayoutSubviews() profileImageView.layer.cornerRadius = profileImageView.frame.height / 2.0 }

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多