当我使用 CATransform3DRotate 设置我的 CALayer 的变换属性时,层被正确旋转。但是,该层的边缘呈锯齿状且未消除锯齿。我读过几篇关于这个主题的文章:
iPhone: CALayer + rotate in 3D + antialias?
iPhone - Jagged Edges when applying perspective to CALayer
我尝试通过在我的对角线层上设置以下属性来采纳他们的建议
CALayer* layer = myView.layer;
layer.shadowOpacity = 0.01;
layer.edgeAntialiasingMask = kCALayerTopEdge | kCALayerBottomEdge | kCALayerRightEdge | kCALayerLeftEdge;
layer.borderWidth = 1.0;
layer.borderColor = [UIColor clearColor].CGColor;
layer.backgroundColor = [UIColor greenColor].CGColor;
我还覆盖了对角线层的 drawLayer:inContext: 方法以确保消除锯齿:
-(void)drawLayer:(CALayer*)layer inContext:(CGContextRef)context
{
CGContextSetAllowsAntialiasing(context, true);
CGContextSetShouldAntialias(context, true);
CGContextSetFillColorWithColor(context, [UIColor greenColor].CGColor);
CGContextFillRect(context, self.bounds);
}
我错过了什么?
最佳答案
从 iOS7 开始,这现在终于可以在每层的基础上实现,并且没有任何像透明像素这样的丑陋 hack 或像光栅化这样的变通方法:
layer.allowsEdgeAntialiasing = YES;
有趣的是,官方 CALayer 文档并未涵盖这一点,但绝对是一个公共(public) API。查看iOS7 API diffs和 Peter Steinberger 关于 Hidden Gems and Workarounds in iOS7 的精彩文章.
关于iphone - CALayer 的抗锯齿对角线边缘,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6245276/