What is the best way to show large UIView on UIScrollView?(在 UIScrollView 上显示大 UIView 的最佳方式是什么?)
问题描述
我有一个大的 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 的最佳方式是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:在 UIScrollView 上显示大 UIView 的最佳方式是什么
基础教程推荐
- Android:getLastKnownLocation(LocationManager.NETWORK_PROVIDER 2022-01-01
- libGDX 从精灵或纹理中获取像素颜色 2022-01-01
- iOS4 创建后台定时器 2022-01-01
- Cocos2d iPhone 非矩形精灵触摸检测 2022-01-01
- iPhone - 获取给定地点/时区的当前日期和时间并将其与同一地点的另一个日期/时间进行比较的正确方法 2022-01-01
- NSString intValue 不能用于检索电话号码 2022-01-01
- 如何从 logcat 中删除旧数据? 2022-01-01
- AdMob 广告未在模拟器中显示 2022-01-01
- navigator.geolocation.getCurrentPosition 在 Android 浏览器上 2022-01-01
- 通过重定向链接在 Google Play 中打开应用 2022-01-01
