Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I draw a dot on the screen on touchesEnded using UIBezierpath

Can someone here please show me how to draw a single dot using UIBezierpath? I am able to draw a line using the UIBezierpath but if I remove my finger and put it back and then remove nothing get drawn on the screen.

- (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];
}
like image 969
newdev1 Avatar asked Apr 05 '13 21:04

newdev1


2 Answers

Your path doesn't include any line or curve segments to be stroked.

Try this instead:

- (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];
}
like image 142
rob mayoff Avatar answered Oct 31 '22 17:10

rob mayoff


I used this code:

 -(void)handleTap:(UITapGestureRecognizer*)singleTap { 
     //draw dot on screen

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

     [self setNeedsDisplay]; 
}
like image 44
mirror Avatar answered Oct 31 '22 15:10

mirror