gpt4 book ai didi

ios - 什么时候应该屏蔽 UITableView 部分单元格的角?

转载 作者:行者123 更新时间:2023-11-28 13:29:37 24 4
gpt4 key购买 nike

我正在尝试通过 indexpath.row 制作圆角截面单元格。有时面具正在运行,但有时却没有。为什么会这样?

这是我的面具代码:

func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) {
if indexPath.row > 0 {
//Child Subjects
let myCell = cell as! SubSubjectTableViewCell

if indexPath.row == 1 {
let rectShape = CAShapeLayer()
rectShape.bounds = myCell.containerView.frame
rectShape.position = myCell.containerView.center
rectShape.path = UIBezierPath(roundedRect: myCell.containerView.bounds, byRoundingCorners: [.topLeft, .topRight], cornerRadii: CGSize(width: 15, height: 15)).cgPath

//Here I'm masking
myCell.containerView.layer.mask = rectShape
}
else if indexPath.row == highSchoolSubject[indexPath.section].childs.count {
let rectShape = CAShapeLayer()
rectShape.bounds = myCell.containerView.frame
rectShape.position = myCell.containerView.center
rectShape.path = UIBezierPath(roundedRect: myCell.containerView.bounds, byRoundingCorners: [.bottomLeft, .bottomRight], cornerRadii: CGSize(width: 15, height: 15)).cgPath

//Here I'm masking
myCell.containerView.layer.mask = rectShape
}
else {
myCell.containerView.layer.mask = nil
}
}
}

我也尝试从 cellForRowAt 方法应用掩码,但没有区别。

结果:

enter image description here

还有为什么它从父单元格的顶部看?

最佳答案

UITableViewCell 在显示之前在内部进行了更改。我建议您在 UITableViewDelegate 的 willDisplayCell 方法中设置 maskToBounds,或者设置相同的大小。

或者你也可以试试这个:

您需要添加 cell.layer.maskToBounds = true

关于ios - 什么时候应该屏蔽 UITableView 部分单元格的角?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57606870/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com