表达式解析为未使用的函数:CGContext.saveGState

时间:2017-03-10 12:04:59

标签: ios swift3 cgcontext

我正在编写用于绘制图像模式的代码但是对于函数CGContext.saveGState(),我收到错误,因为Expression解析为未使用的函数。

任何人都可以帮助在swift 3.0中编写相同内容。以下是代码段:

UIGraphicsBeginImageContext(view.frame.size)
tempImageView.image?.draw(in: CGRect(x: 0, y: 0, width: view.frame.size.width, height: view.frame.size.height))
let context = UIGraphicsGetCurrentContext()
CGContext.saveGState(context!)

提前致谢

2 个答案:

答案 0 :(得分:3)

直接在上下文对象上调用saveGState,如下所示:

context?.saveGState()

而不是:

CGContext.saveGState(context!)

答案 1 :(得分:1)

试试这段代码:

UIGraphicsBeginImageContext(view.frame.size)
tempImageView.image?.draw(in: CGRect(x: 0, y: 0, width: view.frame.size.width, height: view.frame.size.height))
let context = UIGraphicsGetCurrentContext()
context?.saveGState()