【问题标题】:How to get absolute position of point inside CALayer如何获取CALayer内点的绝对位置
【发布时间】:2012-03-09 10:34:34
【问题描述】:

如何获得 CALayer 中 CGPoint 的绝对位置。我需要这个来绘制精确的像素

编辑:绝对屏幕

【问题讨论】:

  • 你所说的“绝对”是什么意思?..相对于最顶层,同一层的像素数,...

标签: iphone objective-c calayer quartz-graphics


【解决方案1】:

递归地测试超级层,直到到达根层:

CGPoint originalPoint = // wherever from you obtain your original point
CALayer *layer = self;
CGPoint point = originalPoint;
while (layer.superlayer)
{
    point = [layer convertPoint:point toLayer:layer.superlayer];
    layer = layer.superlayer;
}

// here `point' will contain the exact position

【讨论】:

  • 出于好奇,我假设该层附加到视图(否则您无法获得绝对定位)....所以为什么不使用循环而不是循环:`[layer convertPoint:指向图层:view.window.layer];'?
  • 同样好的解决方案。但是,是的,它假设一个层有一个关联的视图。
猜你喜欢
  • 2017-12-06
  • 1970-01-01
  • 2021-06-11
  • 2015-04-03
  • 2011-08-03
  • 1970-01-01
  • 2014-08-29
  • 2022-11-02
  • 1970-01-01
相关资源
最近更新 更多