2013-04-05 55 views
3

有人可以在这里请示范我如何使用UIBezierpath绘制一个点。我能够使用UIBezierpath绘制一条线,但是如果我移开手指并将其放回,然后移除画面上的任何东西。 由于如何使用UIBezierpath在touchesEnded的屏幕上绘制一个点

- (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]; 

}

回答

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]; 
} 
+0

完美无瑕。感谢这么多rob – newdev1 2013-04-05 23:00:09

+0

你好@Rob我可以用椭圆形开始吗? – Ranjit 2014-01-23 09:53:42

+0

@Ranjit好的。为什么不?你不需要我的许可。 – 2014-01-23 16:43:14

4

这一次我用

- (空)handleTap:(UITapGestureRecognizer *)singleTap {// 在屏幕上画点

CGPoint tapPoint = [singleTap locationInView:self]; 
[bezierPath_ moveToPoint:tapPoint]; 
[bezierPath_ addLineToPoint:tapPoint]; 

[self setNeedsDisplay]; 

}

相关问题