我正在创建一个CAShapeLayer用作UIView图层的掩码.我用a UIBezierPath来绘制形状图层.它工作得很好,除了我画画时得到一些奇怪的结果.几何体的行为不符合预期.我正试图在右上角绘制简单的"馅饼切片":
#define degreesToRadians(x) ((x) * M_PI / 180.0)
...
// "layer" refer's to the UIView's root layer
CAShapeLayer *maskLayer = [CAShapeLayer layer];
maskLayer.frame =
layer.presentationLayer ?
((CAGradientLayer *)layer.presentationLayer).bounds : layer.bounds;
maskLayer.fillRule = kCAFillRuleEvenOdd;
maskLayer.needsDisplayOnBoundsChange = YES;
CGFloat maskLayerWidth = maskLayer.bounds.size.width;
CGFloat maskLayerHeight = maskLayer.bounds.size.height;
CGPoint maskLayerCenter =
CGPointMake(maskLayerWidth/2,maskLayerHeight/2);
UIBezierPath *path = [UIBezierPath bezierPath];
[path moveToPoint:maskLayerCenter];
[path addArcWithCenter:maskLayerCenter radius:(maskLayerWidth/2)
startAngle:degreesToRadians(0) endAngle:degreesToRadians(90) clockwise:YES];
[path closePath];
maskLayer.path = path.CGPath;
layer.mask = maskLayer;
Run Code Online (Sandbox Code Playgroud)
最终结果是在右下角绘制了饼图切片.弧的第一个点是以90度绘制的,然后是180度.即使我使用0度和90度角,它为什么会这样做?