0
一些視覺上的錯誤我有以下細胞UITableView的佈局:與CALayer的
•UIView的
••的UIImageView
•••半透明疊加的UIView爲的UIImageView子視圖
也有模仿「播放」按鈕和UILabel的圖標視圖,但它們似乎與此錯誤無關。
而且我有以下代碼:
override func layoutSubviews() {
super.layoutSubviews()
createPath()
}
private func createPath() {
let padding = CGFloat(16)
let bottomLineLength = CGFloat(64)
let arcPadding = CGFloat(8)
let width = self.contentView.frame.width
let height = self.contentView.frame.height
if pathLayer != nil {
pathLayer?.removeFromSuperlayer()
}
pathLayer = CAShapeLayer()
let path = UIBezierPath()
path.move(to: CGPoint(x: padding + arcPadding, y: padding))
path.addLine(to: CGPoint(x: width - padding - arcPadding, y: padding))
// Top-Right arc
path.addArc(withCenter: CGPoint(x: width - padding - arcPadding, y: padding + arcPadding),
radius: arcPadding,
startAngle: CGFloat(3 * M_PI/2),
endAngle: CGFloat(M_PI * 2),
clockwise: true)
path.move(to: CGPoint(x: width - padding, y: padding + arcPadding))
path.addLine(to: CGPoint(x: width - padding, y: height - padding - arcPadding))
// Bottom-Right arc
path.addArc(withCenter: CGPoint(x: width - padding - arcPadding, y: height - padding - arcPadding),
radius: arcPadding,
startAngle: CGFloat(M_PI * 2),
endAngle: CGFloat(M_PI/2),
clockwise: true)
path.move(to: CGPoint(x: width - padding - arcPadding, y: height - padding))
path.addLine(to: CGPoint(x: width - padding - bottomLineLength, y: height - padding))
path.move(to: CGPoint(x: padding + bottomLineLength, y: height - padding))
path.addLine(to: CGPoint(x: padding + arcPadding, y: height - padding))
// Bottom-Left arc
path.addArc(withCenter: CGPoint(x: padding + arcPadding, y: height - padding - arcPadding),
radius: arcPadding,
startAngle: CGFloat(M_PI/2),
endAngle: CGFloat(M_PI),
clockwise: true)
path.move(to: CGPoint(x: padding, y: height - padding - arcPadding))
path.addLine(to: CGPoint(x: padding, y: padding + arcPadding))
// Top-Left arc
path.addArc(withCenter: CGPoint(x: padding + arcPadding, y: padding + arcPadding),
radius: arcPadding,
startAngle: CGFloat(M_PI),
endAngle: CGFloat(3 * M_PI/2),
clockwise: true)
pathLayer?.rasterizationScale = 2 * UIScreen.main.scale
pathLayer?.shouldRasterize = true
pathLayer?.strokeColor = UIColor(red: 0xFF/255, green: 0xFF/255, blue: 0xFF/255, alpha: 0.5).cgColor
pathLayer?.lineWidth = 2.0
pathLayer?.path = path.cgPath
contentView.layer.addSublayer(pathLayer!)
}
我稱它在layoutSubviews對於重新創建的設備旋轉的路徑。
如果你看截圖,會看到一些黑色,並在路徑附近旋轉了一些黑色的「洞」。它們全都看起來一樣,並且它們當然不在UIImageView中的圖像上。
我認爲這是關係到我的CALayer。如何解決它?
有一個沿着每個圓角矩形的內部左邊緣的黑色楔子。如果您放大,則可以看到。沿着頂部,右側和左下邊緣也有楔形。 –
@robmayoff我很高興你看到他的意思! – matt