私は円形のチャートを作成しています。ターゲット値を指すために、強調表示された円の端に小さなビューを追加する必要があります(影ではありません)。ストロークエンドポイントに基づいて、円(ハイライト)スーパービューx、y位置を見つけることはできますか?CAShapeLayerのスーパービュー位置を取得するには?
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
更新: 私は実際にはObjective Cの中で時計回りにグラフに取り組んでいます、alexburtnikコードを試してみましたが、それはここでの問題はありません。私はalexburtnikとして言及したが、私は完全に反時計賢明なグラフのために動作すると信じていた。私たちはClockwiseでも動作するようにコードを変更する必要があります。分かっていれば解決策を教えてください。
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:トリックを行う必要があります – Alex