MKMapView的屏幕截图不起作用

时间:2013-03-11 17:56:55

标签: ios xcode mkmapview screenshot

这是我的代码:

我做错了什么?我只想拍一张显示给定位置的MKMapView的截图。截取屏幕截图并将其放置在UIImage中可以正常工作,但MKMapView看起来非常奇怪,就像它没有被渲染一样。怎么了?

if(PageControllerMain.currentPage == 0){

    if ([[UIScreen mainScreen] respondsToSelector:@selector(scale)]) {
        UIGraphicsBeginImageContextWithOptions(MainPage1MapContainer.bounds.size, MainPage1MapContainer.opaque, 0.0);

    }

    else {

        UIGraphicsBeginImageContext(self.view.bounds.size);

    }

    UIGraphicsBeginImageContextWithOptions(MainPage1MapContainer.bounds.size, MainPage1MapContainer.opaque, 0.0);
    [MainPage1MapContainer.layer renderInContext:UIGraphicsGetCurrentContext()];
    UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    NSData * data = UIImagePNGRepresentation(image);
    [data writeToFile:@"MapImagePage1.png" atomically:YES];


    OverallMainMapContainer.image = image;


}

MKMapView doens't display location

0 个答案:

没有答案