ios - 如何在定位

时间:2017-08-11 08:55:47

标签: ios swift calayer cgcontext

我必须将CALayer放在CGContext

所以我在课程render(in: CGContext)中找到了一个函数CALayer:)

但这对我来说还不够:(

因为此功能无法在CALayer

中定位CGContext

所以我尝试设置position的值CALayer,但它没有按预期工作

有没有办法定位它?

这是我的代码。

...

let context: CGContext = UIGraphicsGetCurrentContext()
let myLayer: CALayer = ...

myLayer.position = CGPoint(x: 100, y: 100) // It didn't work as I expected
myLayer.render(in: context)

1 个答案:

答案 0 :(得分:0)

对于仍在寻找该问题解决方案的人们。您可以在这样的上下文中使用translateBy(x:y:)

if let context = UIGraphicsGetCurrentContext() {
    context.translateBy(x: 100.0, y: 100.0)
    myLayer.render(in: context)
}