【发布时间】:2017-03-29 20:13:16
【问题描述】:
我正在制作一个圆形图表,我需要在突出显示的圆圈(不是阴影)的末尾添加小视图以指向目标值。能否根据笔画端点找到一个圆形(高亮)超视图x,y位置?
UIView->Circle(使用CAShapeLayer 和UIBezierPath)。我需要根据结束Circle 笔划值获得UIView 的位置。
请参考此链接(如 23% 虚线)http://support.softwarefx.com/media/74456678-5a6a-e211-84a5-0019b9e6b500/large
提前致谢! Need to find green end circle position
更新: 我已经尝试过 alexburtnik 代码,实际上正在处理目标 c 中的顺时针图,但这在这里不是问题。我尝试过 alexburtnik 提到的,我相信它非常适用于反时钟明智的图表。我们需要对代码进行一些更改以适用于顺时针,如果您知道请给出解决方案。
CGFloat radiusCircle = (self.frame.size.height * 0.5) - ([_lineWidth floatValue]/2.0f);
-(void)addTargetViewWithOptions:(CGFloat)progress andRadius:(CGFloat)radius{
CGFloat x = radius * (1 + (cos(M_PI * (2 * progress + 0.5))));
CGFloat y = radius * (1 - (sin(M_PI * (2 * progress + 0.5))));
UIView *targetView = [[UIView alloc]initWithFrame:CGRectMake(x, y, 40, 30)];
targetView.backgroundColor = [UIColor greenColor];
[self addSubview:targetView];}
我尝试过提到的 esthepiking,在这里我添加了代码和屏幕截图
-(void)addTargetView{
CGFloat endAngle = -90.01f;
radiusCircle = (self.frame.size.height * 0.5) - ([_lineWidth floatValue]/2.0f);
endAngleCircle = DEGREES_TO_RADIANS(endAngle);//-1.570971
// Size for the text
CGFloat width = 75;
CGFloat height = 30;
// Calculate the location of the end of the stroke
// Cos calculates the x position of the point (in unit coordinates)
// Sin calculates the y position of the point (in unit coordinates)
// Then scale this to be on the range [0, 1] to match the view
CGFloat endX = (cos(endAngleCircle) / 2 + 0.5);
CGFloat endY = (sin(endAngleCircle) / 2 + 0.5);
// Scale the coordinates to match the diameter of the circle
endX *= radiusCircle * 2;
endY *= radiusCircle * 2;
// Translate the coordinates based on the location of the frame
endX -= self.frame.origin.x;
endY -= self.frame.origin.y;
// Vertically align the label
endY += height;
// Setup the label
UIView *targetView = [[UIView alloc]initWithFrame:CGRectMake(endX, endY, width, height)];
targetView.backgroundColor = [UIColor redColor];
[self addSubview:targetView];}
【问题讨论】:
-
convertPoint:toView: 应该可以解决问题
标签: ios objective-c calayer uibezierpath cashapelayer