Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/39.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/27.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在iPhone屏幕上用线条画签名?_Iphone_Objective C_Opengl_Quartz Graphics_Paint - Fatal编程技术网

如何在iPhone屏幕上用线条画签名?

如何在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

我想让用户在iPhone屏幕上画一个签名,所以我添加了UIView的一个子类,并为其“touchesMoved”方法添加了一些代码


-(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示例代码对于初学者来说可能太复杂了,我发现。对于大多数初学者来说,这很容易学习。

请记住,用手指书写的签名与用书写工具书写的签名是不同的。您可能需要重新考虑使用签名的目的,以及签名是否具有所需的约束力。

谢谢您的提示。签名只是用作我的应用程序的附加功能。这不是识别用户的唯一方法。