当我使用CATransform3DRotate对CALayer的transform属性进行设置时,图层会正确旋转。但是,图层的边缘是锯齿状的,不会消除锯齿。我读过关于这个问题的一些文章: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);
}
我错过了什么?
太棒了!好帖子。 – tassock 2011-09-11 22:00:11
7.0和更高版本中有一个更好的选择。 http://stackoverflow.com/questions/6245276/anti-alias-diagonal-edges-of-calayer/19443644#19443644 – cbowns 2014-02-28 01:03:10