Ios 如何使用UIBezierpath在触摸屏上绘制点
这里有人能告诉我如何用UIBezierpath画一个点吗?我可以用UIBezierpath画一条线,但是如果我把手指拿出来放回去,然后什么也不拿出来,屏幕上就会画出来Ios 如何使用UIBezierpath在触摸屏上绘制点,ios,objective-c,uibezierpath,Ios,Objective C,Uibezierpath,这里有人能告诉我如何用UIBezierpath画一个点吗?我可以用UIBezierpath画一条线,但是如果我把手指拿出来放回去,然后什么也不拿出来,屏幕上就会画出来 - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event { UITouch *touch = [touches anyObject]; CGPoint p = [touch locationInView:self]; [pPath m
- (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];
}
您的路径不包括任何要笔划的直线或曲线段 请尝试以下方法:
- (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];
}
我使用了以下代码:
-(void)handleTap:(UITapGestureRecognizer*)singleTap {
//draw dot on screen
CGPoint tapPoint = [singleTap locationInView:self];
[bezierPath_ moveToPoint:tapPoint];
[bezierPath_ addLineToPoint:tapPoint];
[self setNeedsDisplay];
}
太好了。非常感谢Rob你好@Rob我可以用椭圆形开始这条路吗?@Ranjit当然可以。为什么不呢?你不需要我的许可。好吧,@robmayoff,你能看看这个并建议我如何做得更好吗