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

Expression resolves to an unused function: CGContext.saveGState

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

任何人都可以帮助在 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!)

提前致谢

只需像这样直接在上下文对象上调用 saveGState:

context?.saveGState()

而不是:

CGContext.saveGState(context!)

试试这个代码:

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()