1

我目前正在使用,MKSnapshotter但我注意到(类似于 MKMapView)它会占用大量内存,并且在应用程序运行期间从不释放它。我试过释放内存但没有用:

-(void)viewWillDisappear:(BOOL)animated{
[super viewWillDisappear:animated];
[self releaseMKMapSnapshotMem];
}

-(void)releaseMKMapSnapshotMem{
    self.snapshotter=nil;//MKSnapShotter
    self.options=nil;//MKSnapShotterOptions
 }

任何帮助是极大的赞赏。

更新 包括更多细节

MKMapSnapshotOptions * snapOptions= [[MKMapSnapshotOptions alloc] init];
        self.options=snapOptions;
        CLLocation * salonLocation = [[CLLocation alloc] initWithLatitude:self.lat longitude:self.long];
        MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance(location.coordinate, 300, 300);
        self.options.region = region;
        self.options.size = self.view.frame.size;
        self.options.scale = [[UIScreen mainScreen] scale];

        MKMapSnapshotter * mapSnapShot = [[MKMapSnapshotter alloc] initWithOptions:self.options];
        self.snapshotter =mapSnapShot;
        [self.snapshotter startWithCompletionHandler:^(MKMapSnapshot *snapshot, NSError *error) {
            if (error) {
                NSLog(@"[Error] %@", error);
                return;
            }

            UIImage *image = snapshot.image;
            self.mapImage = image;
            NSData *data = UIImagePNGRepresentation(image);

            [self saveMapDataToCache:data WithKey:mapName];



        }];
4

1 回答 1

0

尝试这个:

    MKMapSnapshotOptions * snapOptions= [[MKMapSnapshotOptions alloc] init];
    CLLocation * salonLocation = [[CLLocation alloc] initWithLatitude:self.lat longitude:self.long];
    //location.coordinate or salonLocation.coordinate below????
    MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance(location.coordinate, 300, 300);
    snapOptions.region = region;
    snapOptions.size = self.view.frame.size;
    snapOptions.scale = [[UIScreen mainScreen] scale];

    MKMapSnapshotter * mapSnapShot = [[MKMapSnapshotter alloc] initWithOptions: snapOptions];
    [mapSnapShot startWithCompletionHandler:^(MKMapSnapshot *snapshot, NSError *error) {
        if (error) {
            NSLog(@"[Error] %@", error);
            return;
        }
        UIImage *image = snapshot.image;
        NSData *data = UIImagePNGRepresentation(image);

        [self saveMapDataToCache:data WithKey:mapName];

    }];

我做的和你做的差不多,只有两个不同:

    options.region = _mapView.region;
    options.size = _mapView.frame.size;

我的 _mapView 是在视图控制器中显示的地图...

于 2015-03-25T21:55:33.673 回答