Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

I Have bad performance on using shadow effect

I put some image views on scroll view. And when I drag this scroll view, I didn't have any problems.

But after I applied shadow effect to these image views, dragging this scroll view has bad performance.

I used shadowOpacity, shadowRadius and shadowOffset methods.

ex:

[ [ anImageView layer ] shadowOpacity: 1.0 ];

If using shadow effect causes bad performance seriously, I will draw shadow of the images directly.

If there are some tips about this issues, please let me know them.

I want to use shadow effect on iOS programically, because I have the worst drawing skill.

Thank you for your reading.

like image 835
MonsterK Avatar asked Jun 18 '11 09:06

MonsterK


2 Answers

See CALayer.shouldRasterize (iOS 3.2+, but so is shadowOffset/etc):

When the value of this property is YES, the layer is rendered as a bitmap in its local coordinate space and then composited to the destination with any other content. Shadow effects and any filters in the filters property are rasterized and included in the bitmap.

You probably also want to set rasterizationScale appropriately.

like image 124
tc. Avatar answered Oct 04 '22 03:10

tc.


While using the reasterized layer indeed increases the performance you will get better (nicer) results using the shadowpath proerty as @wayne-hartman suggests.

Check http://nachbaur.com/blog/fun-shadow-effects-using-custom-calayer-shadowpaths on how to use the CALayer shadow path.

like image 29
Zdenek Avatar answered Oct 04 '22 02:10

Zdenek