代码之家  ›  专栏  ›  技术社区  ›  Olotiar

获取MKMapView的UIImage

  •  3
  • Olotiar  · 技术社区  · 13 年前

    我有一大堆MKMapView,我想获得它的UIImage(每个UItableViewCell一个)。相当简单,我用;

    UIGraphicsBeginImageContextWithOptions(_map.bounds.size, NO, 0.0);
    [_map.layer renderInContext:UIGraphicsGetCurrentContext()];
    UIImage *mapImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    
    _mapImageView.image = mapImage;
    

    在我的UITableViewCell子类中。

    问题在于: MKMapView 如果 UITableViewCell 不在屏幕上,所以当我滚动 UITableView ,我有一堆 UIImageView 里面有一个灰色的格子。有人能解决这个问题吗?我该如何强制 MK地图视图 要在图形上下文中呈现?

    谢谢

    2 回复  |  直到 13 年前
        1
  •  0
  •   Dustin    13 年前

    当我需要同时渲染整个表视图时,我调整了表视图的大小,使其足够大,可以显示所有单元格。

    更改表的框架,使其高度为numberOfCells*heightOfCell,进行渲染,然后将框架改回。

        2
  •  0
  •   Dustin    13 年前

    This 可能会让我摆脱困境(谷歌静态地图API V2)

    -编辑- 实际上实现了这一点:远没有我想做的那么粗鲁,就像一种魅力。

    推荐文章