为什么第一个单元格与我的表观视图的第二个单元格之间存在表观视图差距? (仅发生在iPhone 11上)
我想创建一个带有圆角(例如Apple Music App)的顶部的桌面视图。因此,我的解决方案是如下代码中对第一个单元格应用修改。
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell
{
guard let cell = tableView.dequeueReusableCell(withIdentifier: "CustomCell", for: indexPath) as? CustomCell
else {
fatalError("The dequeued cell is not an instance of Pack.")
}
if indexPath.row == 0{
cell.roundCorners([.topLeft,.topRight], radius: cR)
}
return cell
}
extension UIView {
func roundCorners(_ corners: UIRectCorner, radius: CGFloat) {
let path = UIBezierPath(
roundedRect: bounds,
byRoundingCorners: corners,
cornerRadii: CGSize(width: radius, height: radius))
let mask = CAShapeLayer()
mask.path = path.cgPath
layer.mask = mask
}
}
我在许多设备上测试了解决方案,并且效果很好,但是当我在iPhone 11上尝试时,第一和第二个单元格之间出现了一个小的1px差距。有人知道为什么吗? iPhone 11有什么特别之处吗?可能是由于不良的习惯,以这种方式绕弯头?
I wanted to create a tableView with a top having rounded corners (like Apple Music app). So my solution was to apply a modification to the first cell as in the code below.
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell
{
guard let cell = tableView.dequeueReusableCell(withIdentifier: "CustomCell", for: indexPath) as? CustomCell
else {
fatalError("The dequeued cell is not an instance of Pack.")
}
if indexPath.row == 0{
cell.roundCorners([.topLeft,.topRight], radius: cR)
}
return cell
}
extension UIView {
func roundCorners(_ corners: UIRectCorner, radius: CGFloat) {
let path = UIBezierPath(
roundedRect: bounds,
byRoundingCorners: corners,
cornerRadii: CGSize(width: radius, height: radius))
let mask = CAShapeLayer()
mask.path = path.cgPath
layer.mask = mask
}
}
I tested the solution on many devices and it worked well, but when I tried on iPhone 11, there was a small 1px gap appearing between the first and second cell. Does anyone knows why? Is there something special with iPhone 11? Could it be due to a bad practice to round corners this way?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
从ios11开始,有一种新的圆角方法,这不会使故障:
there is a newer way to round corners starting from ios11 that doesn't make the glitch: