核心動畫在設計的時候就考慮了效能。它首先是層層級的呈現,並且設計運行在小型的裝置上(iphone和itouch),這些裝置記憶體有限,並且cpu和gpu不如案頭電腦上的強大,核心動畫是被設計的比較高效的,但是並不意味著你就可以在代碼中隨便用。
陰影也是代價很高的。因為他們屬性部分透明的層,它需要大量的計算,來決定每個像素(因為每個像素都需要計算,直到有不透明的層遇到。如果陰影重疊的話,就增加了消耗。考慮限制只有最外層的陰影,並允許內層不產生任何陰影
QuartzCore layer.shadow吸效能。他們需要重新渲染,每次有新的變化,都會造成投影片,Lag,Lag。
http://stackoverflow.com/questions/10133109/fastest-way-to-do-shadows-on-ios/10133182#10133182
Adding a shadowPath should give you a huge performance boost. The following example assumes you only want the shadow on the sides of your view
CGPathRef path = [UIBezierPath bezierPathWithRect:view.bounds].CGPath;[view.layer setShadowPath:path];
EDIT: On default a CALayer draws a shadow during animations, the following code allows you to cache the shadow as a bitmap and reuse it instead of
redrawing it:
self.view.layer.shouldRasterize = YES;// Don't forget the rasterization scale// I spent days trying to figure out why retina display assets weren't working as expectedself.view.layer.rasterizationScale = [UIScreen mainScreen].scale;
還有一個答案是:
You can greatly improve the performance of a CALayer’s shadow by using its shadowPath
property—this
allows it to draw the shadow without having to recalculate the alpha mask of the layer. For a rectangular view, you’d use it like this:
theView.layer.shadowPath = [UIBezierPath bezierPathWithRect:theView.bounds].CGPath;
or, if its corners are rounded,
theView.layer.shadowPath = [UIBezierPath bezierPathWithRoundedRect:theView.bounds cornerRadius:theView.layer.cornerRadius].CGPath;
根據實際情況,提升效能!