Ich erstelle eine App, bei der du letztendlich unterschreiben musst, und ich frage mich, wie du die Signatur löschen würdest, wenn sie versagt hat?Wie entferne ich eine UIBezierPath-Zeichnung?
EDIT:
Schnurklasse:
#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
Und dann in meiner anderen Klasse "SecondViewController", habe ich eine Taste, die mit dem IBAction clearMethod verbunden ist:
-(IBAction)clearMethod:(id)sender{
LinearInterpView *theInstance = [[LinearInterpView alloc] init];
[theInstance clearPath];
}
Es enthält die Zeilenklasse und ruft die clearPath-Methode auf.
Der Teil, der nicht funktioniert ist, was in der ClearPath Funktion ist:
-(void) clearPath{
path = nil;
[self setNeedsDisplay];
}
Für was auch immer Grund, das funktioniert nicht für mich .. – DCAdams
Sie sollten Code von dem, was Sie tun, und markieren, was nicht funktioniert für Sie. –
Okay, ich habe Code und Erklärung hinzugefügt. – DCAdams