iphoneiosuipangesturerecognizer

i want to draw with UIPanGestureRecognizer


i want to draw the paths an user draws in the screen using UIPanGestureRecognizer.

I am using the following functions but without any results.

Please let me know where am i doing wrong.

- (void)pan:(UIPanGestureRecognizer *)sender{

     [[UIColor greenColor]set];
     CGContextRef context=UIGraphicsGetCurrentContext();
     CGContextSetLineWidth(context, 1.0f);


     if (sender.state==UIGestureRecognizerStateBegan) {
         CGContextMoveToPoint(context, [sender locationInView:self.view].x, [sender locationInView:self.view].y);
         NSLog(@"touch phase began");
     }

     CGContextAddLineToPoint(context, [sender locationInView:self.view].x, [sender locationInView:self.view].y);

     if (sender.state==UIGestureRecognizerStateEnded)
         CGContextStrokePath(context);
}

Thank you in Advance


Solution

  • Refer draw-line-with-gesture link where drawing is done with UIPanGestureRecognizer.