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에 의해 기호보기를로드하는 사용하는 경우. 귀하의 행동에 sign view를 다시 초기화하면 – Vinodh
은 경로 객체를 제거하지 않습니다. removeAllPoints 함수를 사용하십시오. –
@deepak 어떤 방법으로 문제를 해결하거나 코드 변경을 수정 하시겠습니까? – Vinodh