gpt4 book ai didi

iphone - 在 Core Graphics 中绘制圆圈 - 为什么这不起作用?

转载 作者:塔克拉玛干 更新时间:2023-11-02 07:52:13 26 4
gpt4 key购买 nike

我正在尝试创建一个简单的绘图应用程序,它可以在您将手指放在任何地方创建圆圈,这就是我所拥有的:

@synthesize touchPos;
@synthesize coords;


- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch = [touches anyObject];
touchPos = [touch locationInView:self.view];
coords.text = [NSString stringWithFormat:@"%3.0f, %3.0f", touchPos.x, touchPos.y];
[self setNeedsDisplay];
}

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
[self touchesBegan:touches withEvent:event];
}

- (void)drawRect:(CGRect)rect
{
CGContextRef contextRef = UIGraphicsGetCurrentContext();
CGContextSetLineWidth(contextRef, 2.0);
CGContextSetRGBFillColor(contextRef, 0, 0, 1.0, 1.0);
CGContextSetRGBStrokeColor(contextRef, 0, 0, 1.0, 1.0);
CGRect circlePoint = (CGRectMake(touchPos.x, touchPos.y, 10.0, 10.0));

CGContextFillEllipseInRect(contextRef, circlePoint);
}

我没有收到任何错误或警告,它只是不绘制任何东西。此外,文本框会在我触摸的任何位置显示坐标,所以我知道这不是问题所在。

最佳答案

此代码需要位于作为当前 View 层次结构一部分的 UIView 子类中。

关于iphone - 在 Core Graphics 中绘制圆圈 - 为什么这不起作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6801395/

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