我的UICollectionView
的细胞上有阴影。我用
NotificationCenter.default.addObserver(self, selector: #selector(self.rotate), name: .UIDeviceOrientationDidChange, object: nil)
func rotate() {
setNeedsLayout()
layoutIfNeeded()
}
并在layoutSubviews()
我重新加载这个影子。在屏幕上出现的单元格中,一切都很好,在单元格中,这一切都很好,但是存在但是在屏幕外(向上或向下)的单元格不会更新。
为什么会这样,以及如何解决这个问题?
这是我的更新影子代码:
circleShadowView.layer.shadowPath = UIBezierPath(roundedRect: circleShadowView.bounds, cornerRadius: circleShadowView.bounds.width / 2).cgPath
circleShadowView.layer.shouldRasterize = true
circleShadowView.layer.rasterizationScale = UIScreen.main.scale
let maskLayer = CAShapeLayer()
let path = CGMutablePath()
path.addRect(circleShadowView.bounds.insetBy(dx: 0, dy: -30))
path.addRoundedRect(in: circleShadowView.bounds, cornerWidth: circleShadowView.bounds.width / 2, cornerHeight: circleShadowView.bounds.width / 2)
maskLayer.path = path
maskLayer.fillColor = UIColor.black.cgColor
maskLayer.fillRule = kCAFillRuleEvenOdd
circleShadowView.layer.mask = maskLayer