views:

419

answers:

2

Hi,

I am trying to move some custom drawing code from a view into a CAShapeLayer, which then get added as a sublayer to the original view's CALayer. This also works well, but when rotating the device, the animation starts to stutter, e.g. you just see the frame in the original orientation and then the final orientation, with at most one frame in between - not smooth at all. Slide-in and slide-out animations of the corresponding UIViewController are a bit jerky, too (but not that much).

All the CAShapeLayer has in its path is one CGPathAddRect, it is set to be opaque, its opacity is 1.0f and the fillColor is set to opaque blue.

When drawing the path directly in the views drawRect method, however, the animation is smooth. So I suppose it has something to do with the CAShapeLayer being animated during the rotation.

Could you tell me how to either get rid of those jerkiness or just hide the CAShapeLayer when animating? Getting back to just draw CGPaths directly is not an option to me because I rely on the ability of CAShapeLayer to animate its path (it is not animated in my tries with rotating the view).

/update: this also happens when the rotating UIViewControllers view contains a view with a subclass of CAGradientLayer as its layerClass (e.g. a view with a gradient layer as background).

Cheers

MrMage

A: 

Well there is a hide property, you could hide the CAShapeLayer then do the animation. Then call a method that un-hides the CAShapeLayer so that you don't see it while it is rotating and then it should be smooth

Jaba
I tried that. It doesn't work. It doesn't even help to completely remove the `CAShapeLayer` in `- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation duration:(NSTimeInterval)duration` and then re-add it in `- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation`.
MrMage
Well you could delloc it and the alloc it and also save it? try that maybe. BTW give me some leeway I am not the greatest wit the iPhone, or even at that coding. just look at my profile and see the questions. I really have very little background behind me. I am only 17. Sorry for the lack of help on my end
Jaba
Are you really sure that the layer is even the problem?
Jaba
Well, if the layer (either a simple `CAGradientLayer` or `CAShapeLayer`) is added to the view, it stutters. If I don't add it, it won't stutter. Maybe I'll try to release, cache and re-alloc the layer, but that's very inelegant and I doubt it'll help.
MrMage
Well if you could use insruments then I would then you could see were the problem is arsing.
Jaba
A: 

Seems like this issue has been fixed by Apple in iOS 4.

MrMage