2016-11-23 1 views
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]; 
     } 
+0

당신이 코드 또는 staorybaord에 의해 기호보기를로드하는 사용하는 경우. 귀하의 행동에 sign view를 다시 초기화하면 – Vinodh

+0

은 경로 객체를 제거하지 않습니다. removeAllPoints 함수를 사용하십시오. –

+0

@deepak 어떤 방법으로 문제를 해결하거나 코드 변경을 수정 하시겠습니까? – Vinodh

답변

0

다음에 지우기 방법을 변경하십시오

- (void)erase 
     { 
      [path removeAllPoints]; 
      path = [UIBezierPath bezierPath]; 
      [path setLineWidth:2.0]; 
      [self setNeedsDisplay]; 

     } 

당신이 아래에 사용할 수있는 작업 삭제 기능을하려면 appocahes :

접근 한

하는 경우 코드를 사용하여 기호보기를로드하는 중입니다. 그는 다음과 같은 코드 :

//ViewController.m 

    #import "SignView.h " 

    @interface MySignatureViewController : UIViewController { 
     SignView* signView; 
    } 

    -(void)viewDidLoad{ 
     signView= [[ mySmoothLineView alloc] initWithFrame: desiredFrame]; 
     [signView setBackgroundColor:[UIColor clearColor]]; 
     [self.view addSubview: signView]; 
    } 

    - (IBAction)clearSign:(id)sender { 
       [signView erase]; 
      } 

접근법 2

당신은 스토리 보드

//ViewController.m 


     #import "SignView.h " 

     @interface MySignatureViewController : UIViewController { 
      @property (nonatomic, weak)SignView* signView; 
     } 



     - (IBAction)clearSign:(id)sender { 
        [self.signView erase]; 
       } 
+0

접근법 1이 작동하지만 signd가 작동하지 않는 것보다 시작하는 viewdidLoad 메소드에 signView를 추가하십시오. clear clear 버튼을 누르면 작동합니다. –