我有以下代码,并且方向在加载时效果很好,但是当方向更改时,它会失真,也就是说,如果加载为纵向并更改为横向,则角半径会失真,就像从圆形变为正方形一样。
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = categoryCV.dequeueReusableCell(withReuseIdentifier: "CategoryCVC", for: indexPath) as! CategoryCollectionViewCell
cell.catLabel.text = cities[indexPath.row].name
cell.catImg.image = UIImage(named:cities[indexPath.row].image)
cell.layer.cornerRadius = cell.layer.frame.size.height/2
cell.layer.borderColor = UIColor.white.cgColor
cell.layer.borderWidth = 2
return cell
}
如何避免这种情况发生?有没有一种方法可以在
cellForItemAt indexpath
中调用viewDidLayoutSubviews()
,然后在此处配置corner radius
? 最佳答案
你能试一下吗
func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator)
{
self.collectionView.reloadData()
self.collectionView.layoutIfNeeded()
}
关于ios - 方向改变时拐角半径失真,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/49551936/