gpt4 book ai didi

ios - UIGraphicsGetCurrentContext 保存旋转状态

转载 作者:搜寻专家 更新时间:2023-11-01 06:27:39 25 4
gpt4 key购买 nike

我正在尝试绘制带有图像的 imageView。

let context = UIGraphicsGetCurrentContext()
context?.translateBy(x: imageView.center.x, y: imageView.center.y)
context?.rotate(by: imageData.rotationAngle)
context?.translateBy(x: -imageView.center.x, y: -imageView.center.y)
imageView.image?.draw(in: imageView.frame)

我在循环内有多个 UIImageViews 并且下一个 imageView 似乎受到先前旋转的影响。

在绘制新的 imageView 之前,我应该如何重置该上下文?

最佳答案

您将要使用:

if let context = UIGraphicsGetCurrentContext() {
CGContextSaveGState(context)
context.translateBy(x: imageView.center.x, y: imageView.center.y)
context.rotate(by: imageData.rotationAngle)
context.translateBy(x: -imageView.center.x, y: -imageView.center.y)
imageView.image?.draw(in: imageView.frame)
CGContextRestoreGState(context)
}

关于ios - UIGraphicsGetCurrentContext 保存旋转状态,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51800329/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com