简体   繁体   中英

What is the best way to show large UIView on UIScrollView?

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.

I placed this main view on UIScrollView . UIScrollView is zoomable and have to show the contents very sharply (It should not get blurred).

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?

Subclass UIView and implement the +layerClass method in it:

+layerClass
{
    return [CATiledLayer class];
}

This causes your view to be backed by CATiledLayer instead of a single, huge CALayer (which would consume too much memory at that size).

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.

I think that you can use tiling with CATiledLayer , to lower the memory pressure, but it all depends about what you are loading, when, and some other aspects. Tiling is a complex topic, you can find more info here

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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