2016-11-23 2 views
0

IはUIViewのデジタル署名に取り組んmです。私はそれを通常このコードで作成しますが、私はボタンのクリックでベジェパスを取り除くことができません。新しい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によって符号ビューをロードしている使用している場合。あなたのアクションでサインビューの再初期化が失敗しました – Vinodh

+0

パスオブジェクトを除外しません。 removeAllPoints関数を使用してください。あなたの問題を修正したり、コードの変更 –

+0

@deepak。 – Vinodh

答えて

0

次に消去方法を変更してください:

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

     } 

あなたは以下を使用することができます削除機能が動作するようにするにはappocahes:

アプローチ1

の場合あなたはコードを使用してサインビューをロードしています彼は、次のコード:

//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を動作していないコードをruningてsign.first時間アプリを描くよりも、working.butないプレス記号クリアボタンが動作しますが動作していない記号を行うよりも、アプリを起動するためにviewDidLoadメソッドにsignViewを追加しています。 clearSignボタンを押してください。 –

関連する問題