CAShapeLayer和UIBezierPath锐度和平滑度

时间:2014-09-21 19:55:04

标签: ios draw uibezierpath smooth cashapelayer

我遇到绘制清晰流畅图形的问题。

这就是我所拥有的:

CGRect photoIconRect = CGRectMake(0, 0, 48, 48);
CAShapeLayer* photoIconLayer = [CAShapeLayer layer];
photoIconLayer.frame = photoIconRect;

UIBezierPath* photoIconPath = UIBezierPath.bezierPath;
[photoIconPath moveToPoint: CGPointMake(32.5, 32)];
[photoIconPath addLineToPoint: CGPointMake(15.5, 32)];
[photoIconPath addCurveToPoint: CGPointMake(14, 30.5) controlPoint1: CGPointMake(14.67, 32) controlPoint2: CGPointMake(14, 31.33)];
[photoIconPath addLineToPoint: CGPointMake(14, 20.5)];
[photoIconPath addCurveToPoint: CGPointMake(15.5, 19) controlPoint1: CGPointMake(14, 19.67) controlPoint2: CGPointMake(14.67, 19)];
[photoIconPath addCurveToPoint: CGPointMake(18, 19) controlPoint1: CGPointMake(15.5, 19) controlPoint2: CGPointMake(16, 19)];
[photoIconPath addCurveToPoint: CGPointMake(21, 16) controlPoint1: CGPointMake(20, 19) controlPoint2: CGPointMake(19, 16)];
[photoIconPath addCurveToPoint: CGPointMake(23, 16) controlPoint1: CGPointMake(23, 16) controlPoint2: CGPointMake(23, 16)];
[photoIconPath addLineToPoint: CGPointMake(25, 16)];
[photoIconPath addCurveToPoint: CGPointMake(27, 16) controlPoint1: CGPointMake(25, 16) controlPoint2: CGPointMake(25, 16)];
[photoIconPath addCurveToPoint: CGPointMake(30, 19) controlPoint1: CGPointMake(29, 16) controlPoint2: CGPointMake(28, 19)];
[photoIconPath addCurveToPoint: CGPointMake(32.5, 19) controlPoint1: CGPointMake(32, 19) controlPoint2: CGPointMake(32.5, 19)];
[photoIconPath addCurveToPoint: CGPointMake(34, 20.5) controlPoint1: CGPointMake(33.33, 19) controlPoint2: CGPointMake(34, 19.67)];
[photoIconPath addLineToPoint: CGPointMake(34, 30.5)];
[photoIconPath addCurveToPoint: CGPointMake(32.5, 32) controlPoint1: CGPointMake(34, 31.33) controlPoint2: CGPointMake(33.33, 32)];
[photoIconPath closePath];
[photoIconPath moveToPoint: CGPointMake(24, 20)];
[photoIconPath addCurveToPoint: CGPointMake(19, 25) controlPoint1: CGPointMake(21.24, 20) controlPoint2: CGPointMake(19, 22.24)];
[photoIconPath addCurveToPoint: CGPointMake(24, 30) controlPoint1: CGPointMake(19, 27.76) controlPoint2: CGPointMake(21.24, 30)];
[photoIconPath addCurveToPoint: CGPointMake(29, 25) controlPoint1: CGPointMake(26.76, 30) controlPoint2: CGPointMake(29, 27.76)];
[photoIconPath addCurveToPoint: CGPointMake(24, 20) controlPoint1: CGPointMake(29, 22.24) controlPoint2: CGPointMake(26.76, 20)];
[photoIconPath closePath];
[photoIconPath moveToPoint: CGPointMake(24, 29)];
[photoIconPath addCurveToPoint: CGPointMake(20, 25) controlPoint1: CGPointMake(21.79, 29) controlPoint2: CGPointMake(20, 27.21)];
[photoIconPath addCurveToPoint: CGPointMake(24, 21) controlPoint1: CGPointMake(20, 22.79) controlPoint2: CGPointMake(21.79, 21)];
[photoIconPath addCurveToPoint: CGPointMake(28, 25) controlPoint1: CGPointMake(26.21, 21) controlPoint2: CGPointMake(28, 22.79)];
[photoIconPath addCurveToPoint: CGPointMake(24, 29) controlPoint1: CGPointMake(28, 27.21) controlPoint2: CGPointMake(26.21, 29)];
[photoIconPath closePath];

[photoIconPath setFlatness: 0.40];
[photoIconLayer setPath: photoIconPath.CGPath];
[photoIconLayer setBackgroundColor:[UIColor colorWithRed: 0 green: 0.5 blue: 1 alpha: 1].CGColor];
[photoIconLayer setFillColor:[UIColor colorWithRed: 1 green: 0.8 blue: 0.133 alpha: 1].CGColor];
[sentView.layer addSublayer:photoIconLayer];

photoIconLayer.masksToBounds = YES;
photoIconLayer.needsDisplayOnBoundsChange = NO;
photoIconLayer.contentsScale = 2.0 * [[UIScreen mainScreen] scale];
photoIconLayer.rasterizationScale = 2.0 * [UIScreen mainScreen].scale;
photoIconLayer.shouldRasterize = YES;

它产生了这个:

enter image description here

即使它在这里看起来并不坏,但在视网膜设备上,镜头环周围仍有明显的锯齿状。我将其与具有流畅图形的其他高端应用进行比较,我肯定觉得我错过了一些东西。

提前致谢。

0 个答案:

没有答案