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