简体   繁体   中英

How Scale context from center in Core Graphics?

I'm drawing with Core Graphics and I need to scale down the current context. I use the CGContextScaleCTM function but this use de origin and not the center. How can I make scale from center?

缩放后,可以使用CGContextTranslateCTM将上下文移动到任意位置。

Change constant as required.

let percentScale : CGFloat = 0.8
context.translateBy(x: rect.size.width * (1.0 - percentScale) * 0.5, y: rect.size.height * (1.0 - percentScale) * 0.5)
context.scaleBy(x: percentScale, y: percentScale)
// ...draw into context

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM