CGContextSaveGState vs UIGraphicsPushContext CGContextSaveGState vs UIGraphicsPushContext ios ios

CGContextSaveGState vs UIGraphicsPushContext


UIGraphicsPushContext(context) pushes context onto a stack of CGContextRefs (making context the current drawing context), whereas CGContextSaveGState(context) pushes the current graphics state onto the stack of graphics states maintained by context. You should use UIGraphicsPushContext if you need to make a new CGContextRef the current drawing context, and you should use CGContextSaveGState when you're working with one graphics context and just want to save, for example: the current transform state, fill or stroke colors, etc.


UIGraphicsPushContext(ctx) is useful when you want to draw with UIkit and the current context is not the context which you want to draw in.You use this function to make the context which you want to draw in become current context.CGContextSaveGState(ctx) save context (referred by ctx),later you can restore the context use CGContextRestoreGState()


matomo