Show MKMapView in UITableViewCell without slow down UI

前端 未结 2 1358
醉梦人生
醉梦人生 2021-01-05 22:16

i\'m trying to put a MKMapView in some UiTableViewCell but (on iPhone 5, so even in other devices), when the app load the cell with the map, the scroll become not too smooth

2条回答
  •  猫巷女王i
    2021-01-05 22:38

    I ended up using MKMapSnapshotter for the devices that support this awesome and fast function and using Google Static Maps Api for the devices that run iOS6. I think is the best and fast solution that i can get.

    Thanks to @Rob for the suggestion.

    if ( IS_IOS7 ) {
    
        // Placeholder
        cell.objectImage.image = [UIImage imageNamed:@"mapPlaceholder"];
    
        // Cooridinate
        MKCoordinateRegion region;
        region.center = activity.object.location.coordinate;
        MKCoordinateSpan span;
        span.latitudeDelta = 0.055;
        span.longitudeDelta = 0.055;
        region.span = span;
        [self.mapViewForScreenshot setRegion:region animated:NO];
    
        MKMapSnapshotOptions *options = [[MKMapSnapshotOptions alloc] init];
        options.region = self.mapViewForScreenshot.region;
        options.scale = [UIScreen mainScreen].scale;
        options.size = CGSizeMake(300, 168);
    
        MKMapSnapshotter *snapshotter = [[MKMapSnapshotter alloc] initWithOptions:options];
        [snapshotter startWithCompletionHandler:^(MKMapSnapshot *snapshot, NSError *error) {
    
            UIImage *image = snapshot.image;
            [cell.objectImage setImage:image];
            cell.mapPinImageView.hidden = NO;
    
        }];
    
    }else{
    
        cell.mapPinImageView.hidden = NO;
        [cell.objectImage setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://maps.googleapis.com/maps/api/staticmap?center=%f,%f&zoom=14&size=600x338&maptype=roadmap&sensor=false&key=APIKEY",activity.object.location.coordinate.latitude, activity.object.location.coordinate.longitude]] placeholderImage:nil];
    
    }
    

    enter image description here

提交回复
热议问题