【问题标题】:Expression resolves to an unused function: CGContext.saveGState表达式解析为未使用的函数:CGContext.saveGState
【发布时间】:2017-03-10 12:04:59
【问题描述】:

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

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

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

提前致谢

【问题讨论】:

    标签: ios swift3 cgcontext


    【解决方案1】:

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

    context?.saveGState()
    

    代替:

    CGContext.saveGState(context!)
    

    【讨论】:

    • @Van 为了表示感谢,您可以按复选标记将我的答案选为正确。
    • @Van 没关系,但我提前两分钟回复了 :)
    【解决方案2】:

    试试这个代码:

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

    【讨论】:

    • @Van 如果我的回答真的对你有帮助,那就点赞我的回答,这样其他人也可以从中获得帮助。
    猜你喜欢
    • 2015-06-15
    • 1970-01-01
    • 1970-01-01
    • 2015-03-30
    • 2016-04-22
    • 2015-11-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多