我正在创建一个应用程序,在最终需要签名的地方,我想知道如果用户签名错误,应该如何清除签名?
编辑:
行类:
#import "LinearInterpView.h"
@implementation LinearInterpView
{
UIBezierPath *path; // (3)
}
- (id)initWithCoder:(NSCoder *)aDecoder // (1)
{
if (self = [super initWithCoder:aDecoder])
{
self.backgroundColor = UIColor.whiteColor;
[self setMultipleTouchEnabled:NO]; // (2)
[self setBackgroundColor:[UIColor whiteColor]];
path = [UIBezierPath bezierPath];
[path setLineWidth:2.0];
}
return self;
}
- (void)drawRect:(CGRect)rect // (5)
{
[[UIColor blackColor] setStroke];
[path stroke];
}
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch = [touches anyObject];
CGPoint p = [touch locationInView:self];
[path moveToPoint:p];
}
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch = [touches anyObject];
CGPoint p = [touch locationInView:self];
[path addLineToPoint:p]; // (4)
[self setNeedsDisplay];
}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
[self touchesMoved:touches withEvent:event];
}
- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event
{
[self touchesEnded:touches withEvent:event];
}
-(void) clearPath{
path = nil;
path = [UIBezierPath bezierPath];
[self setNeedsDisplay];
}
@end
在我另一个类"SecondViewController"中,我有一个按钮与IBAction clearMethod连接:
-(IBAction)clearMethod:(id)sender{
LinearInterpView *theInstance = [[LinearInterpView alloc] init];
[theInstance clearPath];
}
它包含了Line类并调用了clearPath方法。
不起作用的部分是clearPath函数内部的内容:
-(void) clearPath{
path = nil;
[self setNeedsDisplay];
}