問題描述
我有一個大的 UIView
.它的大小可變.它可能大于 5000x5000 size
.我使用 UIBezierPath
在其上繪制線條、圓圈.我還在上面添加了一些 view
.這些 subview
中的每一個都包含 buttons
、textview
、labels
等.
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
.問題是,由于內存壓力問題,它占用了太多的
memory
和崩潰
.
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
而不是單個巨大的 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 的最佳方式是什么?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!