简体   繁体   中英

CALayer overwrites contents-image with background

I have a custom UIView with a custom CALayer. The Layer overwrites -(void)display; to assign a CGImageRef to the layers contents-property. In principle this works as expected(most of the time) but on some devices the view sometimes becomes plain white. Actually I can choose the color by setting a backgoundColor.

Some devices means: out of my 3 test-devices only the iphone5 with iOS7 fails. iPhone6+ and iPad both with iOS8 work.

Sometimes means: In principle it works also on the bad devices but there is about a 50-50-chance to get the actual image or plain background...

(I'm waiting on feedback of some testers to get get better statistics)

Actually I hope to firgure out what method of the layer or the view(as delegate) I have to overwrite empty to stop this ugly behaviour.

Alternatively I will try to add my layer as a sublayer of the normal layer of view. But I would like to avoid that because I would end up with 2 layers in the size of the view which is quite large...

Hope some has a hint for me... Thanks in advance

Update: it's not restricted to iOS7 I also have a report from an iPad running iOS8.4...

Update 2: I found out some more. It looks to me that it's not a problem of the compositing of the layer, but rather one of CGBitmapContext.
I create a bitmap-context and hold a reference to it in order to render additional parts while keeping some of the old content.
Afterwards I call CGBitmapContextCreateImage() and set he resulting image as contents of the layer.
The image will not contain erverything I have rendered. For testing I implemented that I can trigger the update of the contents via touch-event:

  • if I keep an reference to the image and set the same image again to the contents porperty it shows that the same areas remain white (so actually the layer displays the image correctly)
  • if I call CGBitmapContextCreate() again and set the result as content of the layer the image is complete. There is no change to the bitmap-context in the meantime. That means that 2 consequtive calls to CGBitmapContextCreate() return different images?!?

    -

I stopped figuring int out. I start to to consider it a bug in Core-Graphics/Animation. Or a abuse by me. It happens only for quite large views.

First attempts with CATiledLayer don#t make me very happy but seem a feasable approach... Or at least a pointer in the direction I will reorganize my code...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM