【问题标题】:Transform a CGRect in Core Graphic coordinates在核心图形坐标中转换 CGRect
【发布时间】:2016-05-21 04:03:30
【问题描述】:

有没有办法将带有UIView 系统坐标的CGRect 转换为Core Graphics 坐标,原点在左下角?

【问题讨论】:

  • stackoverflow.com/questions/506622/… 使用移动到视图高度并翻转 y 比例的标准技术。 CGContextScaleCTM(ctx, 1.0, -1.0); CGContextTranslateCTM(ctx, 0, -imageRect.size.height);

标签: ios uiview core-graphics


【解决方案1】:

当然。您只需从视图的高度中减去 y 原点和矩形的高度。

rect.origin.y = view.frame.size.height-(rect.origin.y+rect.size.height)

您可以像这样使用CGAffineTransform 来表示它:

CGAffineTransformMakeTranslation(0, view.size.height-((rect.origin.y*2.0)+rect.size.height))

当您现在使用相对值而不是绝对值时,将原点减去两次。


但是,如果您只想翻转上下文以在您想要的 UIView 坐标中工作:

CGFloat ctxHeight = CGContextGetClipBoundingBox(c).size.height;
CGContextScaleCTM(c, 1, -1);
CGContextTranslateCTM(c, 0, -ctxHeight);

【讨论】:

  • 你知道使用CGAffineTransform的方法吗?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2012-03-13
  • 2023-03-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多