在UIScrollView上显示大型UIView的最佳方法是什么? [英] What is the best way to show large UIView on UIScrollView?
问题描述
我有一个很大的 UIView
。它的大小可变。它可能大于5000x5000 大小
。我使用 UIBezierPath
在其上绘制线条,圆圈。我还在其上添加了一些视图
。这些子视图
中的每一个都包含按钮
, textview
, 标签
等。
I have an large UIView
. Its variable size. It may be larger than 5000x5000 size
. I draw lines, circles on it using UIBezierPath
. Also I add some view
's on it. Each of these subview
's contains buttons
, textview
, labels
, etc.
我把这个主视图放在 UIScrollView
。 UIScrollView
是 zoomable
并且必须非常清晰地显示内容(不应该模糊)。
I placed this main view on UIScrollView
. UIScrollView
is zoomable
and have to show the contents very sharply (It should not get blurred).
目前,我绘制完整的 UIView
并添加到 UIScrollView
。问题是,由于内存压力问题,它占用了太多
内存
和崩溃
。
Currently, I draw complete UIView
and added on UIScrollView
. The problem is that, Its taking too much memory
and crashing
because of Memory Pressure Issue.
我应该如何处理以实现高性能?
How should I handle this to achieve high performance?
推荐答案
子类UIView并在其中实现 + layerClass
方法:
Subclass UIView and implement the +layerClass
method in it:
+layerClass
{
return [CATiledLayer class];
}
这会导致您的视图由 CATiledLayer <支持/ code>而不是单个巨大的
CALayer
(这会占用过多的内存)。
This causes your view to be backed by CATiledLayer
instead of a single, huge CALayer
(which would consume too much memory at that size).
然后你只需在自定义视图类中实现 - (void)drawRect:(CGRect)rect
并全部执行你的画在那里。最近我必须在我的项目中执行此操作,该项目使用UIScrollViews滚动可以大到10000 x 150000的区域。
Then you just implement -(void)drawRect:(CGRect)rect
in your custom view class and do all of your drawing in there. I had to do this recently in my project which uses UIScrollViews to scroll over an area that can be as big as 10000 x 150000.
这篇关于在UIScrollView上显示大型UIView的最佳方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!