我正在尝试在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/