I have UIScrollView and number of objects (UIView compositions) with UIImageViews inside them. Some of UIImageViews has round border (I use myImageView.layer.masksToBounds = YES; for this). Other has rectangle borders and part of image in them (I use Clip subviews property in Interface Builder for this).
The issue is that I found that clip properties strongly affect the performance while scrolling:
For iPod touch (4th generation) results of profiling:
- with enabled clip properties (both or one of them) I have around 30 fps while scrolling
- with disabled clip properties I have all 60 fps while scrolling
I really need to clip some images to round bounds and other to rectangle bounds (to show part of image). So, here is my question: what ways there are to improve performance? May be there are low level ways to do it (drawRect: or something), or may be it would be useful to play around alfa masking or I just do something wrong?
When you have graphically intensive masks and things, a simple and easy way to improve performance (often times dramatically) is to set
shouldRasterizetoYESon the layer for that item:This will rastersize the view into a buffer, so it isn’t constantly re-rendered. This will take up a extra memory for each view, so you should really try and recycle/reuse views as you scroll, similar to how a table view does.
For correct behaviour on retina display you also need to set an appropriate value for
rasterizationScale:I’ve had great success with this for things like scrolling photo galleries, where each item had rounded corners, shadows, etc.