Tôi đang làm việc trên biểu đồ hình tròn và tôi cần thêm chế độ xem nhỏ ở cuối vòng tròn được đánh dấu (không phải bóng) để trỏ vào giá trị đích. Tôi có thể tìm thấy một vòng tròn (đánh dấu) siêu xem x, y vị trí dựa trên điểm kết thúc đột quỵ?Làm thế nào để có được vị trí giám sát CAShapeLayer?
UIView->Circle
(sử dụng CAShapeLayer
và UIBezierPath
). Tôi cần đặt vị trí UIView
dựa trên giá trị kết thúc Circle
đột quỵ.
Vui lòng tham khảo liên kết này (như 23% với đường chấm chấm) http://support.softwarefx.com/media/74456678-5a6a-e211-84a5-0019b9e6b500/large
Cảm ơn trước! Need to find green end circle position
Cập nhật: Tôi đã thử alexburtnik mã, thực tế đang làm việc trên đồng hồ khôn ngoan đồ thị trong mục tiêu c nhưng điều đó không phải là một vấn đề ở đây. Tôi đã cố gắng như alexburtnik đã đề cập, tôi tin rằng nó hoàn toàn hoạt động cho đồ thị khôn ngoan chống đồng hồ. Chúng ta cần phải thực hiện một số thay đổi trong mã để làm việc cho chiều kim đồng hồ quá, xin vui lòng cho giải pháp nếu bạn biết.
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];}
Và tôi đã cố gắng như esthepiking đề cập, ở đây tôi thêm mã và ảnh chụp màn hình
-(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: nên làm thủ thuật – Alex