I'm creating an app where you eventually have to sign, and I was wondering how you would clear the signature if they messed up?
EDIT:
Line Class:
#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
And then in my other class "SecondViewController", I have a button which is connected to the IBAction clearMethod:
-(IBAction)clearMethod:(id)sender{
LinearInterpView *theInstance = [[LinearInterpView alloc] init];
[theInstance clearPath];
}
It contains the Line Class and calls the clearPath Method.
The part that is not working is what is inside of the clearPath function:
-(void) clearPath{
path = nil;
[self setNeedsDisplay];
}
To reset the UIBezierPath you should use -removeAllPoints
set the bezierPath
to nil
which clears the old bezier path! and call [self setNeedsDisplay]
on the view where you draw the signature!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With