有人可以告诉我如何使用UIBezierpath绘制单个点。我可以使用UIBezier路径绘制一条线,但是如果我移开我的手指并将其放回去,然后移除屏幕上的任何内容。 感谢
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch = [touches anyObject];
CGPoint p = [touch locationInView:self];
[pPath moveToPoint:p];
[pPath stroke];
[self setNeedsDisplay];
}
- (void)drawRect:(CGRect)rect
{
[pPath stroke];
}
答案 0 :(得分:4)
您的路径不包含任何要描边的线段或曲线段。
请改为尝试:
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
CGPoint p = [touches.anyObject locationInView:self];
static CGFloat const kRadius = 3;
CGRect rect = CGRectMake(p.x - kRadius, p.y - kRadius, 2 * kRadius, 2 * kRadius);
pPath = [UIBezierPath bezierPathWithOvalInRect:rect];
[self setNeedsDisplay];
}
- (void)drawRect:(CGRect)rect {
[[UIColor blackColor] setFill];
[pPath fill];
}
答案 1 :(得分:4)
这个我用的是
- (void)handleTap:(UITapGestureRecognizer *)singleTap { //在屏幕上绘制点
CGPoint tapPoint = [singleTap locationInView:self]; [bezierPath_ moveToPoint:tapPoint]; [bezierPath_ addLineToPoint:tapPoint]; [self setNeedsDisplay];
}