如何在iPhone屏幕上用线条画签名?
我想让用户在iPhone屏幕上画一个签名,所以我添加了UIView的一个子类,并为其“touchesMoved”方法添加了一些代码如何在iPhone屏幕上用线条画签名?,iphone,objective-c,opengl,quartz-graphics,paint,Iphone,Objective C,Opengl,Quartz Graphics,Paint,我想让用户在iPhone屏幕上画一个签名,所以我添加了UIView的一个子类,并为其“touchesMoved”方法添加了一些代码 -(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { UITouch *touch = [touches anyObject]; firstTouch = [touch locationInView:self]; CGSize mySize = CGSizeMa
-(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];
}
我用小矩形画它,结果是一点一点的。因为它太难看了,我想用线来画签名。但是如何区分firstTouch和lastTouch呢?如果我只使用“touchesMoved”方法,我只能获得一个接触点。根据,您还需要实施–触摸开始:with事件:
和–touchesEnded:withEvent:
在实现这些方法之后,您应该能够获得足够的数据来实现路径bezier曲线或其他合适的解决方案 [edit]一个更好的解决方案可能是,一旦控制器收到一个
–触摸移动:带事件:
通知。此外,还可能证明有帮助。因为GLPaint示例代码对于初学者来说可能太复杂了,我发现。对于大多数初学者来说,这很容易学习。请记住,用手指书写的签名与用书写工具书写的签名是不同的。您可能需要重新考虑使用签名的目的,以及签名是否具有所需的约束力。谢谢您的提示。签名只是用作我的应用程序的附加功能。这不是识别用户的唯一方法。