以下是模拟器和保存图片的截图:
代码:
UIGraphicsBeginImageContext(self.view.bounds.size);
[self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *screenshotImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
//guru - just for simulator
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *filePath = [[paths objectAtIndex:0] stringByAppendingPathComponent:@"Image.png"];
[UIImagePNGRepresentation(screenshotImage) writeToFile:filePath atomically:YES];
//end guru
UIImageWriteToSavedPhotosAlbum(screenshotImage, nil, nil, nil);
如何解决此问题?当我使用Xcode4_iOS6构建它时工作正常,但不适用于Xcode5_iOS7。
答案 0 :(得分:2)
你可以用这种方式修复它:
if([self IS_IOS_7])
{
UIGraphicsBeginImageContextWithOptions(self.view.bounds.size, TRUE, [[UIScreen mainScreen] scale]);
}
else
{
UIGraphicsBeginImageContext(self.view.bounds.size);
}
[self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *screenshotImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
UIImageWriteToSavedPhotosAlbum(screenshotImage, nil, nil, nil);
iOS7检查:
-(bool)IS_IOS_7
{
NSString *currOsVersion = [[UIDevice currentDevice] systemVersion];
float sysver = [currOsVersion floatValue] ;
if(sysver >=7.0f)
return true;
return false;
}