如何删除 UIBezierPath 绘图?

DCA*_*ams 6 drawing objective-c ios uibezierpath

我正在创建一个应用程序,你最终必须签名,我想知道如果签名搞砸了,你将如何清除签名?

编辑:

线路类别:

#import "LinearInterpView.h"

@implementation LinearInterpView
{
    UIBezierPath *path; // (3)
}

- (id)initWithCoder:(NSCoder *)aDecoder // (1)
{
    if (self = [super initWithCoder:aDecoder])
    {
        self.backgroundColor = UIColor.whiteColor;
        [self setMultipleTouchEnabled:NO]; // (2)
        [self setBackgroundColor:[UIColor whiteColor]];
        path = [UIBezierPath bezierPath];
        [path setLineWidth:2.0];
    }
    return self;
}

- (void)drawRect:(CGRect)rect // (5)
{
    [[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]; // (4)
    [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) clearPath{

    path = nil;
    path = [UIBezierPath bezierPath];
    [self setNeedsDisplay];

}

@end
Run Code Online (Sandbox Code Playgroud)

然后在我的另一个类“SecondViewController”中,我有一个连接到 IBAction clearMethod 的按钮:

-(IBAction)clearMethod:(id)sender{

     LinearInterpView *theInstance = [[LinearInterpView alloc] init];
    [theInstance clearPath];

}
Run Code Online (Sandbox Code Playgroud)

它包含线路类并调用clearPath 方法。

不起作用的部分是clearPath函数内部的部分:

-(void) clearPath{

        path = nil;
        [self setNeedsDisplay];

}
Run Code Online (Sandbox Code Playgroud)

小智 6

要重置 UIBezierPath 您应该使用 -removeAllPoints


Tej*_*uri 3

设置bezierPathnil清除旧的贝塞尔路径!并调用 [self setNeedsDisplay]您绘制签名的视图!