简体   繁体   English

UIView UIImageView如何优化?

[英]How optimized is UIView UIImageView?

In a game I'm building I want to make a UIView that represents a tiled map. 在我正在构建的游戏中,我想制作一个表示平铺地图的UIView。 I'd like to know if a UIView filled with a grid of UIImageViews would lag when animated around the screen? 我想知道填充UIImageViews网格的UIView在屏幕上动画时是否会滞后? My first thought is that if UIVIew was really optimized the subviews would know not to draw themselves if they weren't on screen, but I don't know the details of how UIView optimizes drawing. 我的第一个想法是,如果真的对UIVIew进行了优化,则子视图将不会在未显示在屏幕上时自行绘制,但是我不知道UIView如何优化绘制的细节。

Also, if this approach is possible, is there an upper bound on how many 64x64 pixel tiles I could have in one view before it has issues? 此外,如果可以采用这种方法,那么在出现问题之前我在一个视图中可以拥有多少个64x64像素图块是否有上限?

If you want to represent a tiled map, why not use CATiledLayer ? 如果要表示平铺地图,为什么不使用CATiledLayer This is what provides support for the tiling seen in, for example, Maps. 这就是为例如在Maps中看到的平铺提供支持的原因。 It provides asynchronous drawing of tiles with crossfading, support for different zoom levels, etc. 它提供具有交叉淡入淡出的图块异步绘制,支持不同的缩放级别等。

If you were to go with your original idea, I would suggest that you remove imageviews that are offscreen (assuming a large-enough grid to begin with). 如果您要遵循最初的想法,建议您删除屏幕外的图像视图(假设网格足够大)。 It's easy enough to do that with the scrollview delegate methods. 使用scrollview委托方法很容易做到这一点。 Given that, any lag you experience would probably be due to trying to process a bunch of image data on the main thread (which is one benefit of CATiledLayer ; all the drawing happens on background threads). 鉴于此,您遇到的任何延迟都可能是由于尝试在主线程上处理一堆图像数据(这是CATiledLayer一项优势;所有绘制都发生在后台线程上)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM