iphone - 在CGPoint touchPoint上绘制圆

标签 iphone objective-c ios ipad core-graphics

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

相关文章:

iphone - 为什么应用程序从词典获取数据时崩溃?

iphone - 验证文本字段 : highlighted red border, iPhone

ios - 在 iOS 9 中提取企业应用程序的 IPA

iphone - 在 ios 键盘上方显示建议工具栏

objective-c - 使用仪器泄漏和对象分配 : Are autoreleased objects counted as leaks?

ios - 移动广告网络如何在不需要修改广告应用程序的情况下跟踪应用程序安装?

objective-c - iOS 圆形 float

ios - 如何将 NSCoding 协议(protocol)与枚举一起使用?

iphone - 子项目的 Xcode 环境变量

iphone - 这里如何获取和修改一个像素值?