我测试了样本应用,可以复制黑角问题。
在进行了一些实验之后,黑角问题似乎与表层的沥滤有关。 电池层的地貌似乎很重要:
- On the first paint, the cell is asked to be painted into a rect. Your code is painting a rounded path, but clipped out the corners. As the underlying tableview is already drawn, no problem occurs. The rect zone is cached, with its corners unpainted.
- When the controller is pushed, a cached image is stored, with rectangular placeholders for the cells.
- When the controller is popped, the cached image and the cells are drawn. But the place to draw cells is rectangular but the cell s cached image is not, leading to black corners.
为了消除黑角,你可以:
- Make sure that all the cell s rect is painted. This means using the same color to file the cell before drawing the edge as the tableview s background color. If your tableview use the default background color, you can use
[UIColor groupTableViewBackgroundColor].CGColor
as filling color; it is a pattern based color and follows device orientation (yeah); but the painting is not perfectly aligned with the background (damn).
- Use a CALayer mask on the cell s layer. This implies creating a mask
CGImage
, set it as the layer s content and assign the mask layer to the cell s layer. Not sure about the performance.
希望能帮助。
<>Update>
经过一些失败的尝试,我放弃了掩盖思想,因为它过于模糊。
我重新阅读了手机层的代码,找到了一种简单的方式去除黑角。 基本想法是,只有显示梯度的颜色,才能完全透明。 通过使用以下<代码> 方法,黑角消失(在模拟器上和在装置上):
- (void)display {
if (_override) {
self.colors =
[NSArray arrayWithObjects:
(id)[UIColor colorWithRed:colorComponents[0] green:colorComponents[1] blue:colorComponents[2] alpha:colorComponents[3]].CGColor,
(id)[UIColor colorWithRed:colorComponents[4] green:colorComponents[5] blue:colorComponents[6] alpha:colorComponents[7]].CGColor,
nil];
} else {
self.colors =
[NSArray arrayWithObjects:
(id)[UIColor clearColor].CGColor,
(id)[UIColor clearColor].CGColor,
nil];
}
[super display];
}
当然,这可以优化:
- Create the color arrays once.
- Provide a custom setter for
override
property that change the layer s colors.
- Remove the
display
method as it is no needed anymore.