Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 如何使用UIBezierpath在触摸屏上绘制点_Ios_Objective C_Uibezierpath - Fatal编程技术网

Ios 如何使用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

这里有人能告诉我如何用UIBezierpath画一个点吗?我可以用UIBezierpath画一条线,但是如果我把手指拿出来放回去,然后什么也不拿出来,屏幕上就会画出来

- (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,你能看看这个并建议我如何做得更好吗