2016-09-15 159 views
14

我想这条线转换为雨燕3当前语法的代码,但似乎也存在一些问题:斯威夫特3和CGContextDrawImage

CGContextDrawImage(context, CGRect(x:0.0,y: 0.0,width: image!.size.width,height: image!.size.height), image!.cgImage) 

按照CoreGraphics.apinotesCGContextDrawImage转化为CGContext.draw

Name: CGContextDrawImage 
    # replaced by draw(_ image: CGImage, in rect: CGRect, byTiling: Bool = false) 
    SwiftName: CGContext.__draw(self:in:image:) 
    SwiftPrivate: true 

当我尝试做:

CGContext.draw(context as! CGImage, in: CGRect(x:0.0, y:0.0, width: image!.size.width, height: image!.size.height), byTiling: false) 

似乎还有一些简单的语法,扰乱编译器,但我看不到(其实我收到一个典型的模棱两可的错误):

enter image description here

谁能帮我这个新雨燕3语法的代码?

回答

32

你需要调用它,仿佛它是CGContext一个实例方法:

context.draw(image!.cgImage!, in: CGRect(x: 0.0,y: 0.0,width: image!.size.width,height: image!.size.height)) 

检查the latest reference of CGContext

+0

谢谢你,它完美的作品。 'self'这个例子的初始属性让我分心:) –

+0

可爱的感谢队友 –