In my prototype app there are around 100 CALayers at different but fixed positions with the same small image as the content. The only thing necessary now is to toggle the hidden
property repeatedly and very quickly.
This works, but it's noticably slower than with my previous approach using UIImage
's drawAtPoint:
method in drawRect
.
I want a strobe-like look, no transitions. That's why I'm using hidden
and not opacity
, but still, it kind of looks like there's a fade and that tells me it's slow.
With the drawAtPoint:
-approach it looked good, but it was heavy on the CPU.
Fo this reason I rewrote it using CALayer and now I'm puzzled why it is that slow.
Can you give me advice how to investigate this? With Instruments I didn't gain any insight. It tells me it's rendering at 59-60 FPS but visibly it's much slower.
It seems like there's a delay between the (touch) events and the hiding or showing of the layers taking effect.
That's how I'm initializing the layers:
layers[i] = [CALayer layer];
layers[i].frame = frameForLayer(i);
layers[i].contents = (__bridge id)image;
[layers[i] setContentsScale:scale];
layers[i].hidden = YES;
[[self layer] addSublayer:layers[i]];
All that in the awakeFromNib
in my main view.
Later, only the hidden
properties are modified, the rest stays.
EDIT:
Instead of just the someLayer.hidden = NO
, I'm now writing
[CATransaction begin];
[CATransaction setValue:(id)kCFBooleanTrue
forKey:kCATransactionDisableActions];
someLayer.hidden = NO;
[CATransaction commit];