我有一个水平的UICollectionView,在每个单元格中都有视图。基于用户的选择,我必须突出显示单元格,因此在每个单元格中添加了一个UIView并将边缘添加到该视图中。就像在图片中一样。
我的代码
let edge:CGFloat = 5.0
path.move(to: CGPoint(x: edge, y: 0.0))
path.addLine(to: CGPoint(x: self.frame.width - edge, y: 0.0))
path.addLine(to: CGPoint(x: self.frame.width - (edge * 2), y: self.frame.height))
path.addLine(to: CGPoint(x: 0.0 , y:self.frame.height))
path.addLine(to: CGPoint(x: edge, y: 0.0))
path.close()
let mask = CAShapeLayer()
mask.path = path.cgPath
layer.mask = mask
这第一次很好用,但是当我尝试突出显示其他单元格时,我看不到边缘。
试图弄清楚我在做什么错。当选择了其他单元格时,我也正在重新加载CollectionView,但仍然出现这种奇怪的行为。 谢谢