我希望可以使用中心点和角度画一条线。我需要画线才能沿着圆圈移动。但我无法让它工作。我不知道怎么能做到这一点!我尝试使用以下代码将线条旋转指定角度,但它不起作用。因为我还很新,所以我不明白我在哪里犯错了!!如果我使用下面的代码,这就是它的样子
- (void)drawThumbAtPoint:(CGPoint)sliderButtonCenterPoint inContext:(CGContextRef)context {
//Vertical line
CGPoint newPoint = [self convertPoint:sliderButtonCenterPoint toView:self];
CGFloat angleInRadians = (CGFloat)M_PI/180.0f * currentAngle;
CGFloat distance = 15;
CGPoint point = CGPointMake(newPoint.x + distance * sinf(angleInRadians), newPoint.y + distance * cosf(angleInRadians));
UIGraphicsPushContext(context);
CGContextBeginPath(context);
UIBezierPath *path = [UIBezierPath bezierPath];
path.lineWidth = 10.f;
[path moveToPoint:sliderButtonCenterPoint];
[path addLineToPoint:point];
[[UIColor redColor] set];
[path stroke];
// CGAffineTransform rot = CGAffineTransformMakeRotation(angleInRadians);
// [path applyTransform:rot];
UIGraphicsPopContext();
}
和,
CGPoint thumbCenterPoint = CGContextGetPathCurrentPoint(context);
[self drawThumbAtPoint:thumbCenterPoint inContext:context];