MKMapView的内存使用率很高 [英] Memory usage of MKMapView is very high
问题描述
所以我有一个带有UIPageControl的UIScrollView,其中有一堆MKMapViews(大多数是15种不同的地图).加载此视图后,该应用程序确实很缓慢,使用几分钟后,我收到了内存警告.我在Instruments中查看了它,地图占用了大量内存.有时甚至高达200mb.我能想到的一件事是重用mapViews.但是由于视图的结构方式,编码复杂度增加了.有什么建议可以改善我的表现吗?
So i have a UIScrollView with UIPageControl which has a bunch of MKMapViews (mostly 15 different maps). The app is really sluggish once this view loads and after a few minutes of usage i get a memory warning. I looked at it in Instruments and the maps take an insanely high chunk of memory. Even upto ~200mb sometimes. One thing i can think of is to reuse the mapViews. But because of how the views are structured the coding complexity increases. Any suggestions how i can improve performance?
这是我的应用程序的结构:
This is how my app is structured:
我有一个具有UIScrollView的视图控制器,该控件用于水平滚动.在scrollView中,我从包含mkmapview的视图控制器数组中读取了子视图.
I have a view controller which has a UIScrollView which i use for horizontal scrolling. In the scrollView i read subviews from an array of view controllers which contains the mkmapview.
希望是有道理的!在编码时,我使用Apple的pageControl示例应用程序作为参考点,因此设计大致相似.
Hope that made sense! I used Apple's pageControl sample app as a point of reference while coding so the design is roughly similar.
提前谢谢!
编辑:因此,我尝试添加单个mapView实例并在滑动时更改坐标.它仍然需要相当数量的内存.
So i tried adding a single instance of the mapView and changing the coordinates on swiping. It still takes a decent amount of memory.
推荐答案
要在滚动视图中滚动任意数量的页面,您只需要两个内容视图,而不是15.这是因为永远不会超过两个内容在任何给定时间可见的视图.您可以在UIScrollView
委托的-scrollViewDidScroll:
方法中重新布置内容.
To scroll through an arbitrary number of pages in a scroll view you only need two content views, not 15. That's because there'll never be more than two content views visible at any given time. You can re-layout your content in the UIScrollView
delegate's -scrollViewDidScroll:
method.
这篇关于MKMapView的内存使用率很高的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!