gpt4 book ai didi

iphone - 在CGPoint touchPoint上绘制圆

转载 作者:行者123 更新时间:2023-12-01 19:17:42 25 4
gpt4 key购买 nike

我正在尝试在UITouch的确切位置绘制一个圆(像点一样小)。

问题是,当我从用户触摸获得touchPoint时,我必须随后绘制放置圆的Rect

为了计算Rect的原点,将其放置为使其内部的圆以原始接触点为中心的位置,我使用了毕达哥拉斯定理。

但是,这种方法不是很好,也不精确。

有一个更好的方法吗?

UITouch *touch = obj;
CGPoint touchPoint = [touch locationInView:self.view];

CGContextAddEllipseInRect(context,(CGRectMake ((touchPoint.x - 5.7), (touchPoint.y - 5.7)
, 9.0, 9.0)));

最佳答案

你可以像下面这样

  CFFloat radius=10;
UITouch *touch = obj;
CGPoint touchPoint = [touch locationInView:self.view];

CGContextAddEllipseInRect(context,(CGRectMake ((touchPoint.x - radius/2), (touchPoint.y
- radius/2)
, radius, radius)));

关于iphone - 在CGPoint touchPoint上绘制圆,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12143666/

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