本文介绍了在iOS上使用resizableImages时避免混合图层的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图避免在iOS上混合图层以提高性能。但是,我注意到我在 UITableViewCell backgroundView 中使用的可调整大小的图像被标记为混合图像层:

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:

实际上,使用任何可调整大小的图像(甚至是不透明的JPEG)都会导致图层混合,如此屏幕截图所示,首先使用PNG,然后使用JPEG作为 UIImageView 中可调整大小的图像。不需要混合图层的唯一可调整大小的图像是1x1像素图像,在底部可见:

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:

避免这种情况的方法? Core Animation分析是一种不精确的艺术(对我来说是不精确的),但我认为这是导致滚动表格视图时将其降至25 FPS的主要原因。

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:经过更多的实验,我发现如果仅垂直或水平拉伸图像(PNG或JPG),则不会将其标记为混合层。但是,经过更多的实验,我认为这可能是因为仅在一维拉伸的图像较小。我的图像没有被视为100x100的混合图像,而是150x100的图像。

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.

推荐答案

我创建了一个非常宽的图像,并且只垂直拉伸了它。这不需要混合图层,并且可以实现我的表格视图单元格的正确效果。这并不理想,但是由于高度太小,视网膜图像仍然只有236个字节。

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.

这篇关于在iOS上使用resizableImages时避免混合图层的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-26 10:26