gpt4 book ai didi

ios - 如何使用 UIBezierpath 在 touchesEnded 的屏幕上画一个点

转载 作者:可可西里 更新时间:2023-11-01 04:22:39 24 4
gpt4 key购买 nike

有人可以告诉我如何使用 UIBezierpath 绘制一个点吗?我可以使用 UIBezierpath 画一条线,但如果我移开手指再放回去,然后再移开,屏幕上就不会绘制任何东西。

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch = [touches anyObject];
CGPoint p = [touch locationInView:self];
[pPath moveToPoint:p];
[pPath stroke];
[self setNeedsDisplay];
}

- (void)drawRect:(CGRect)rect
{
[pPath stroke];
}

最佳答案

您的路径不包含任何要描边的直线或曲线段。

试试这个:

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
CGPoint p = [touches.anyObject locationInView:self];
static CGFloat const kRadius = 3;
CGRect rect = CGRectMake(p.x - kRadius, p.y - kRadius, 2 * kRadius, 2 * kRadius);
pPath = [UIBezierPath bezierPathWithOvalInRect:rect];
[self setNeedsDisplay];
}

- (void)drawRect:(CGRect)rect {
[[UIColor blackColor] setFill];
[pPath fill];
}

关于ios - 如何使用 UIBezierpath 在 touchesEnded 的屏幕上画一个点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15844057/

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