I want the user to draw a signature on the iPhone screen, so I add a subclass of UIView and add some code to my "touchhesMoved" method.
-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { UITouch *touch = [touches anyObject]; firstTouch = [touch locationInView:self]; CGSize mySize = CGSizeMake(5, 5); UIGraphicsBeginImageContext(mySize); CGContextRef ctx = UIGraphicsGetCurrentContext(); CGContextBeginPath(ctx); CGContextSetRGBFillColor(ctx, 1, 0, 0, 1); CGContextAddRect(ctx, CGRectMake(0, 0, 5, 5)); CGContextFillPath(ctx); UIImage *redRect = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); UIImageView *redRectView = [[UIImageView alloc] initWithImage:redRect]; redRectView.center = CGPointMake(firstTouch.x, firstTouch.y); [self addSubview:redRectView]; }
I draw it in small rectangles and it turns out to be accurate. Since this is too ugly, I want to draw the signature in lines. But how to distinguish between firstTouch and lastTouch? If I use the "touchsMoved" method, I can only get one touch point.
source share