1

I use Core Graphics to draw in an UIView, and cache the contents in a CGLayer.

One of its functions needs to duplicate a sub-area of the CGLayer and move it to a new location within the same layer. As a traditional trick, I used to do this by drawing the layer into its own context.

However, the behavior of this trick is "undefined" according to the documentation, and it stops working in iOS 12.

Is there an alternative way to do this efficiently? (I have tried drawing the sub-area into an CGImage then drawing the result image back to the layer. But this method seems sort of slow and not so memory efficient.:()

Terry
  • 337
  • 2
  • 9
  • When you say that it seems sort of slow, have you measured the performance difference? – David Rönnqvist Sep 13 '18 at 09:22
  • Is your question about finding an alternative solution for drawing the same content in a view multiple times? – David Rönnqvist Sep 13 '18 at 09:24
  • Hi, @David Rönnqvist , what I am looking for is an alternative solution to copy a sub-area in a CGLayer, then move this duplicated part to a new location in the same layer. In another word, moving a sub-area within the layer. The reason I say it is slower is that the difference is obvious to me from bare eyes (because there is a step to make the copy of the area and generate an image.) – Terry Sep 13 '18 at 09:57

0 Answers0