【发布时间】:2020-12-29 12:05:56
【问题描述】:
let renderer = UIGraphicsImageRenderer(size: CGSize(width: 500, height: 500))
let image = renderer.image { context in
let size = renderer.format.bounds.size
UIColor.red.setFill()
context.cgContext.fillEllipse(in: CGRect(x: 0, y: 0, width: size.width, height: size.height))
let x = 300 //center
let y = 100 //center
let w = 200
let h = 60
let r = 5.41 //radians
UIColor.white.setFill()
context.cgContext.fill(CGRect(x: x - w / 2, y: y - h / 2, width: w, height: h))
}
结果是这样的:
在上下文中绘制之前,如何旋转我的白色矩形,旋转中心位于矩形中间?
【问题讨论】:
-
太晚了,你已经画好了。没有“绘制的对象”,只有像素。这些像素现在完成了。在绘制白色矩形之前,您应该已经转换了上下文。
-
@matt,我可以把旋转的矩形放在那里吗?
-
是的,当然。但是你不能现在旋转它。
-
你完全正确,我改变了我的问题。
-
好的,但你不旋转矩形。您旋转上下文并将矩形绘制到其中。
标签: ios swift core-graphics