0
我在致力于数字签名UIView
。我通过这段代码创建它,但我无法删除按钮单击时的贝塞尔路径。点击按钮时不会创建新的BezierPath
。我分享我的代码,请看我的代码。删除UIBezierPath绘图?
//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];
}
你通过加载代码或staorybaord迹象视图。在您的操作中,标记视图的重新初始化未能清除标记 – Vinodh
不要删除路径对象。使用removeAllPoints函数。 –
@deepak哪种方法可以修复您的问题或清除代码更改 – Vinodh