views:

153

answers:

2

I've got several UIViews that have a layer class of CATiledLayer because they need to be zoomed using UIScrollViews. I use Quartz to render some PDF pages inside said UIViews. Everything is fine until I try to animate said views frames on page rotation.

The animation is fine, the contents of the view gets scaled quickly and cheaply to match the new frame size. After the animation I call setNeedsDisplay to re-render the whole thing. Now before my -(void)drawLayer:(CALayer*)layer inContext:(CGContextRef)ctx get's called (but after setNeedsDisplay) the views contents shortly reverts back to the previous state (with the remaining pixels being stretched edge pixels in cases where the contents becomes smaller than the view). This results in a flash of some very annoying graphical distortion before reverting back to normal thanks to the new "render pass".

After a lot of debugging I've managed to sort out that this definitely happens during the actual drawing cycle (rather than the application run cycle where I do setNeedsDisplay) but before -(void)drawLayer:(CALayer*)layer inContext:(CGContextRef)ctx even gets called.

What's the sanest way of avoiding or further debugging this?

Edit: I've thrown together a very simple project that demonstrates this effect perfectly. http://dl.dropbox.com/u/1478968/EEBug.zip PS: There's a sleep(2) in the rendering code just so that the effect could be better observed on screen.

A: 

how about some code sample?

maxpower
I posted some sample code.
Joonas Trussmann
A: 

My guess is that pdf rendering is done by the CPU, and takes a fair amount of time to texture load any pdf renderings from CPU memory into the GPU memory for actual display. So your new UIView rendering might be getting displayed before all your updated pdf layer pixels makes it to the GPU.

You best bet may be to pre-render the new pdf images at the new scale factor into another offscreen CALayer before the UIView setNeedsDisplay, give it time to upload to the GPU (you may have to profile/tune for the bus bandwidth of the worse case device you support), and then finish your view animation while quickly flipping between old and new CALayers.

hotpaw2