Sam*_*ikh 11 angle cashapelayer ios uibezierpath
我使用UIBezierPath和CAShapeLayer在iOS中编码了半圈.
clockWiseLayer = [[CAShapeLayer alloc] init];
CGFloat startAngle = -M_PI_2;
CGFloat endAngle = M_PI + M_PI_2;
CGFloat width = CGRectGetWidth(imageView.frame)/2.0f + 30;
CGFloat height = CGRectGetHeight(imageView.frame)/2.0f +50;
CGPoint centerPoint = CGPointMake(width, height);
float radius = CGRectGetWidth(imageView.frame)/2+10;
clockWiseLayer.path = [UIBezierPath bezierPathWithArcCenter:centerPoint
radius:radius
startAngle:startAngle
endAngle:endAngle
clockwise:YES].CGPath;
clockWiseLayer.fillColor = [UIColor clearColor].CGColor;
clockWiseLayer.strokeColor = [UIColor blueColor].CGColor;
clockWiseLayer.borderColor = [UIColor greenColor].CGColor;
clockWiseLayer.backgroundColor = [UIColor redColor].CGColor;
clockWiseLayer.strokeStart = 0.0f;
clockWiseLayer.strokeEnd = 0.5f;
clockWiseLayer.lineWidth = 2.0f;
clockWiseLayer.borderWidth = 5.0f;
clockWiseLayer.shouldRasterize = NO;
[self.layer addSublayer:clockWiseLayer];
Run Code Online (Sandbox Code Playgroud)
结果如下.
我希望在世界地球仪的另一侧有这个蓝色半圈.
它是半圈,但我想在另一边,也是CounterClockWise.
我无法设置开始和结束角度,顺时针方向:否.
谢谢.
Grz*_*ski 24
检查坐标文档:http: //i.stack.imgur.com/1yJo6.png
与数学中的标准坐标系相比,Y轴是相反的.
您应该从1/2*PI(底部锚点)绘制到3/2*PI(顶部锚点)然后将strokeStart设置为0.0f并将strokeEnd设置为1.0f(因此它将填充整个路径).
使用iOS常量的工作代码:
CGFloat startAngle = M_PI_2;
CGFloat endAngle = startAngle + M_PI;
CGFloat width = CGRectGetWidth(imageView.frame)/2.0f;
CGFloat height = CGRectGetHeight(imageView.frame)/2.0f;
CGPoint centerPoint = CGPointMake(width, height);
float radius = CGRectGetWidth(imageView.frame)/2+10;
CAShapeLayer* clockWiseLayer = [[CAShapeLayer alloc] init];
clockWiseLayer.path = [UIBezierPath bezierPathWithArcCenter:centerPoint
radius:radius
startAngle:startAngle
endAngle:endAngle
clockwise:YES].CGPath;
clockWiseLayer.fillColor = [UIColor clearColor].CGColor;
clockWiseLayer.strokeColor = [UIColor blueColor].CGColor;
clockWiseLayer.borderColor = [UIColor greenColor].CGColor;
clockWiseLayer.backgroundColor = [UIColor redColor].CGColor;
clockWiseLayer.strokeStart = 0.0f;
clockWiseLayer.strokeEnd = 1.0f;
clockWiseLayer.lineWidth = 2.0f;
clockWiseLayer.borderWidth = 5.0f;
[self.layer addSublayer:clockWiseLayer];
Run Code Online (Sandbox Code Playgroud)
你从圆圈顶部开始-M_PI_2,结束于M_PI + M_PI_2(如果你想要有一个完整的圆圈并限制它使用strokeEnd,strokeStart).然后将圆路径设置为从路径末端的一半(图像的左侧)而不是从开始到一半(图像的右侧)绘制
CGFloat startAngle = -M_PI_2;
CGFloat endAngle = M_PI + M_PI_2;
clockWiseLayer.strokeStart = .5f;
clockWiseLayer.strokeEnd = 1.0f;
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
9375 次 |
| 最近记录: |