gpt4 book ai didi

ios - 如何删除 UIBezierPath 绘图?

转载 作者:可可西里 更新时间:2023-11-01 05:33:02 26 4
gpt4 key购买 nike

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

编辑:

线类:

#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

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

-(IBAction)clearMethod:(id)sender{

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

}

它包含Line Class并调用clearPath方法。

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

-(void) clearPath{

path = nil;
[self setNeedsDisplay];

}

最佳答案

要重置 UIBezierPath,您应该使用 -removeAllPoints

关于ios - 如何删除 UIBezierPath 绘图?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37887629/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com