Avoiding blended layers when using resizableImages

2019-05-01 09:16发布

问题:

I'm trying to avoid blended layers on iOS to improve performance. However, I notice that the resizable image I'm using for the backgroundView of my UITableViewCell is being marked as a blended layer:

In fact, using any resizable image--even a JPEG with no transparency--caused layer blending, as seen in this screenshot where first a PNG and then a JPEG is used as a resizable image in a UIImageView. The only resizable image that didn't require a blended layer was a 1x1 pixel image, seen at the bottom:

Is there any way to avoid this? Core Animation profiling is imprecise art (atleast to me), but I think it's a main contributor to dropping to around 25 FPS when scrolling my table view.

Edit2: Upon more experimentation, I found that if I only vertically or horizontally stretched the images (either a PNG or JPG), they weren't marked as blended layers. However, upon even more experimentatio I think this may be because the images only stretched in one dimension are smaller. My image is not being treated as blended at 100x100, but it is at 150x100.

回答1:

I created a very wide image and only stretched it vertically. This did not require blended layers, and achieves the correct effect for my table view cell. This isn't ideal, but because of the small height it's still only 236 bytes for the retina image.