i have a scroll view loaded with 3 view controllers. each view controller is drawing its layers with that code –
(there us more then that but I pulled it out to check if it will help). still i have very crappy sliding.
any help ?
shani
CALayer *sublayer = [CALayer layer];
sublayer.backgroundColor = [Helper cardBackGroundColor:card].CGColor;
sublayer.shadowOffset = CGSizeMake(0, 3);
sublayer.shadowRadius = 5.0;
sublayer.shadowColor = [UIColor blackColor].CGColor;
sublayer.shadowOpacity = 0.8;
sublayer.frame = CGRectInset(self.view.layer.frame, 20, 20);
sublayer.borderColor = [UIColor blackColor].CGColor;
sublayer.borderWidth = 2.0;
sublayer.cornerRadius = 10.0;
[self.view.layer addSublayer:sublayer];
Drawing things with
CALayeroften yields poor performance. We usually use a stretchable image to get adequate performance. When you think of it, it does make sense to render it before hand rather than using the iPhone’s limited processing power to render it in real time.It’s possible that you can get adequate performance from
CALayer, but drawing a png will probably still be faster, thus saving battery life time.EDIT: So here’s an example to explain the concept.
This code actually replaced a CALayer drawing that was too slow.
shadow.pngis 34 by 34 pixels and contains a shadowed square. Thanks to the stretchable image it’s possible to resize the square without stretching the shadow. For more information about this I would suggest reading the documentation forstretchableImageWithLeftCapWidth:topCapHeight:. Also Google will help you find guides on how to work with stretchable images. If you have more questions I’ll be happy to answer them.