Guardando y restaurando CGContext
Estoy intentando guardar y restaurar un CGContext para evitar realizar cálculos pesados de dibujo por segunda vez y obtengo el error<Error>: CGGStackRestore: gstack underflow
.
¿Qué estoy haciendo mal? ¿Cuál es la forma correcta de hacer esto?
- (void)drawRect:(CGRect)rect {
CGContextRef context = UIGraphicsGetCurrentContext();
if (initialized) {
CGContextRestoreGState(context);
//scale context
return;
}
initialized = YES;
//heavy drawing computation and drawing
CGContextSaveGState(context);
}