views:

664

answers:

2

I am using a CALayer to display a path via drawLayer:inContext delegate method, which resides in the view controller of the view that the layer belongs to. Each time the user moves their finger on the screen the path is updated and the layer is redrawn. However, the drawing doesn't keep up with the touches: there is always a slight lag in displaying the last two points of the path. It also flickers, but only while displaying the last two-three points again. If I just do the drawing in the view's drawRect, it works fine and the drawing is definitely fast enough.

Does anyone know why it behaves like this? I suspect it is something to do with the layer buffering, but I couldn't find any documentation about it.

A: 

You might have better luck using a layer hosting view.

Instead of using the drawLayer:inContext: method, setup the view you want and add a CALayer to it:

UIView *layerHosting = [UIView new];
[layerHosting setLayer:[[CALayer new] autorelease]];

Hope that helps!

alfwatt
I've never seen `[UIView new]` before (but it really exists according to Apple's docs). I recommend using `[[UIView alloc] initWithFrame:frame]` and `[CALayer layer]`, however, because that's the way they are meant to be used.
MrMage
A: 

[UIView new] is simply shorthand for [[UIView alloc] init]