CGContextRef context = ...; ... CGContextSaveGState (context); { [drawable drawWithContext: context inRect: bounds withMetrics: self.metrics]; // or whatever drawing you're doing } CGContextRestoreGState (context);Edit: Gus Meuller of Flying Meat fame has a block-based utility that does this:void FMCGContextHoldGState (CGContextRef context, void (^block)()) { CGContextSaveGState(context); { block (); } CGContextRestoreGState(context); }and if you're wanting to do something similar withNSGraphicsContext
s:void FMNSContextHoldGState (void (^block)()) { [NSGraphicsContext saveGraphicsState]; { block (); } [NSGraphicsContext restoreGraphicsState]; }