Я работаю над цифровой подписью на UIView
. Обычно я создаю его с помощью этого кода, но я не могу удалить путь Безье при нажатии кнопки. Новый BezierPath
не создается при нажатии на кнопку. Я делюсь своим кодом, пожалуйста, посмотрите на мой код.
//Create Class for UIView
#import "SignView.h"
{
UIBezierPath *path;
}
- (id)initWithCoder:(NSCoder *)aDecoder
{
if (self = [super initWithCoder:aDecoder])
{
[self setMultipleTouchEnabled:NO];
[self setBackgroundColor:[UIColor whiteColor]];
path = [UIBezierPath bezierPath];
[path setLineWidth:2.0];
}
return self;
}
- (void)drawRect:(CGRect)rect
{
[[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];
[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)erase
{
path = nil;
path = [UIBezierPath bezierPath];
[path setLineWidth:2.0];
[self setNeedsDisplay];
}
//viewController.m
- (IBAction)clearSign:(id)sender {
SignView *clrView = [[SignView alloc]init];
[clrView erase];
}