地图 - ios的MKMapView在缩放时内存暴涨
PHP中文网
PHP中文网 2017-04-17 17:26:18
0
3
527

ios的mkmapview在zoom时内存会暴涨,并且降不下来。
我在网上搜了很多,也尝试了很多解决方案,比如切换地图显示模式(MKMapType)、不用时释放掉地图。但是并没有明显的解决缩放时的内存问题。

PHP中文网
PHP中文网

认证高级PHP讲师

reply all(3)
阿神

This memory will increase to dozens of megabytes, which is normal.

Mapview uses tiledLayer (tiled Layer). For rendering speed, map tiles are cached in memory.
When zooming, map tiles will be cached at different levels.

I guess when memory is tight, MKMapView will clear the cache by itself, so I don’t think you need to worry about this issue.

PS:1 This is the solution given by stackoverflow, I really don’t understand why.

- (void)applyMapViewMemoryHotFix{

    switch (self.mapView.mapType) {
        case MKMapTypeHybrid:
        {
            self.mapView.mapType = MKMapTypeStandard;
        }

            break;
        case MKMapTypeStandard:
        {
            self.mapView.mapType = MKMapTypeHybrid;
        }

            break;
        default:
            break;
    }


    self.mapView.mapType = MKMapTypeStandard;



}
-(void)mapView:(MKMapView *)mapView regionDidChangeAnimated:(BOOL)animated
{
    [self applyMapViewMemoryHotFix];
}

PS:

Personally I prefer

override func viewDidDisappear(animated: Bool) {
    super.viewDidDisappear(animated)
    mapView.removeFromSuperview()
}

Release the map in the viewDidDisappear method, and then reinitialize it when you need it.

左手右手慢动作

Solution found:

In the regionDidChange method of mapview, it is judged that if map.zoomLevel is less than a certain range, alternate mapType

This can effectively reduce the memory peak.

Because when the map is reduced to a certain range, details such as shops on it should have been cleared to save memory.

Ty80

In the regionDidChange method of mapview, it is judged that if map.zoomLevel is less than a certain range, alternate mapType

This can effectively reduce the memory peak.
How is it done? ? ? ? ? Does mapView have the zoomLevel attribute? ? ?

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!