gpt4 book ai didi

ios - 为什么给 addArcWithCenter 一个 0 度的 startAngle 会使它从 90 度开始?

转载 作者:IT王子 更新时间:2023-10-29 07:59:58 25 4
gpt4 key购买 nike

我正在创建一个 CAShapeLayer 用作 UIView 层的 mask 。我正在使用 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;

最终的结果是在右下角绘制了一个饼图切片。圆弧的第一个点以 90 度绘制,然后向下绘制到 180 度。即使我使用 0 度和 90 度角,为什么它会这样做?

最佳答案

这张图片直接来自the documentation .

image

并且讨论了它是如何工作的(给定默认坐标系)

Discussion
This method adds the specified arc beginning at the current point. The created arc lies on the perimeter of the specified circle. When drawn in the default coordinate system, the start and end angles are based on the unit circle shown in Figure 1. For example, specifying a start angle of 0 radians, an end angle of π radians, and setting the clockwise parameter to YES draws the bottom half of the circle. However, specifying the same start and end angles but setting the clockwise parameter set to NO draws the top half of the circle.

这就是 addArcWithCenter:radius:startAngle:endAngle:clockwise: 角度的工作原理。如果这不是您所看到的,那么您计算的角度不正确。

关于ios - 为什么给 addArcWithCenter 一个 0 度的 startAngle 会使它从 90 度开始?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16192254/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com