iOS 地图截屏

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/coly6203/article/details/51939209
上一次截屏的代码真是又丑又长, 看看大神是怎么写的吧
- (nullable UIImage *)generateSnapshot:(CGSize)size
{
    self.addressLabelBg.hidden = YES;
    self.addressLabel.hidden = YES;
    self.mapView.showsUserLocation = NO;

    CGPoint mapCenter = self.mapView.center;
    UIGraphicsBeginImageContextWithOptions(size, NO, 0.0f);
    [self.mapView drawViewHierarchyInRect:CGRectMake(-(mapCenter.x - size.width / 2),
                                                     -(mapCenter.y - size.height / 2),
                                                     self.mapView.bounds.size.width,
                                                     self.mapView.bounds.size.height)
                       afterScreenUpdates:YES];
    UIImage *snapshotImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();

    self.addressLabelBg.hidden = NO;
    self.addressLabel.hidden = NO;
    self.mapView.showsUserLocation = YES;

    return snapshotImage;
}
其实重点还是截屏区域坐标的确定


阅读更多
换一批

没有更多推荐了,返回首页