If I save and restore the CurrentGraphicsContext, will that revert my drawing back to original state?

StackOverflow https://stackoverflow.com/questions/21972937

  •  15-10-2022
  •  | 
  •  

Вопрос

I have an iPad app where I draw a grid of dates along the x axis and times down the y axis. I then draw colored bars (using CGContext methods) in specific sections of this grid (see image).

If I change the data that is used to draw the bars, the old bars are still visible and the new bars are not. If I use -CGContextSaveGState and -CGContextSaveGState, will that "clear" the old data so the grid is as it was originally without any bars?

enter image description here

Это было полезно?

Решение 2

No. Just the graphical context is restored (graphical engine state machine), not what the engine has produced.

Другие советы

I think Vincent answered your question, but what you need to do now is to redraw all the bars from scratch on the background grid. Call setNeedsDisplay for the view that draws the background and the bars when the bar parameters change. Your drawRect should then recreate the grid and bars.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top