Salvando e restaurando o CGContext
Eu estou tentando salvar e restaurar um CGContext para evitar fazer cálculos de desenho pesados pela segunda vez e estou recebendo o erro<Error>: CGGStackRestore: gstack underflow
.
O que estou fazendo de errado? Qual é a maneira correta de fazer isso?
- (void)drawRect:(CGRect)rect {
CGContextRef context = UIGraphicsGetCurrentContext();
if (initialized) {
CGContextRestoreGState(context);
//scale context
return;
}
initialized = YES;
//heavy drawing computation and drawing
CGContextSaveGState(context);
}