查看Stackoverflow,您可以找到一些代码,允许您对CALayers的边框进行抗锯齿处理,类似于:
layer.borderColor = [UIColor whiteColor].CGColor;
CGFloat borderWidth = 1;
layer.borderWidth = borderWidth;
layer.allowsEdgeAntialiasing = YES;
layer.edgeAntialiasingMask = kCALayerLeftEdge | kCALayerRightEdge + kCALayerTopEdge | kCALayerBottomEdge;
layer.needsDisplayOnBoundsChange = NO;
layer.rasterizationScale = [UIScreen mainScreen].scale;
但对于视网膜显示器,绘制1像素宽的边框会很不错。所以我改变了我的边界:
CGFloat borderWidth = 1 / [[UIScreen mainScreen] scale];
唯一的问题是,之后您可以在用户滚动时看到边缘“闪烁”。它肯定比没有抗锯齿更好,但不如我想要的那么顺畅。有没有人想出让图层不闪烁?
答案 0 :(得分:0)
我知道,这不是最新的,但也许contentsScale会做到这一点。 在Swift中看到整个事情
let layer = view.layer
layer.borderColor = UIColor.white.CGColor
let borderWidth = CGFloat(1.0)
layer.borderWidth = borderWidth
layer.allowsEdgeAntialiasing = true
layer.edgeAntialiasingMask = [.LayerBottomEdge, .LayerTopEdge, .LayerLeftEdge, .LayerRightEdge]
layer.needsDisplayOnBoundsChange = false
layer.rasterizationScale = UIScreen.mainScreen().scale
layer.contentsScale = UIScreen.mainScreen().scale