2014-09-28 40 views
0

7此工作正常,但在iOS 8中,当我附加图像时,屏幕截图为白色屏幕。屏幕截图仅在iOS 8中附加白色图像在iOS 6中使用UIGraphicsGetImageFromCurrentImageContext

奇怪的是,如果我取消,然后重新尝试,它工作正常..

这是代码;

[savingPhotoAlert dismissWithClickedButtonIndex:0 animated:YES]; 

    UIGraphicsBeginImageContext(self.view.bounds.size); 

    [self.view.layer renderInContext:UIGraphicsGetCurrentContext()]; 

    UIImage *screenshotImage = UIGraphicsGetImageFromCurrentImageContext(); 

    UIGraphicsEndImageContext(); 

回答

2

你取消了什么?它是一种alertView吗?你必须指定屏幕截图的时间(afterScreenUpdates = YES)。

- (UIImage *) screenshot { 
    UIGraphicsBeginImageContextWithOptions(self.view.bounds.size, NO, [UIScreen mainScreen].scale); 

    [self.view drawViewHierarchyInRect:self.view.bounds afterScreenUpdates:YES]; 

    UIImage *image = UIGraphicsGetImageFromCurrentImageContext(); 
    UIGraphicsEndImageContext(); 
    return image; 
} 
+0

这是一个张贴到Twitter的功能,从而使图像连接,使用SLComposeViewController所以它提供了一个“取消”和“后”按钮,如果我尝试张贴的图片,我可以看到一个白色屏幕附件,但如果我取消它,并再试一次,它可以正常工作,并且会继续工作。我不确定上面的代码适合我的项目......因为我不能把它放在twitter发布代码中。 – user3355723 2014-09-29 09:50:09

+1

尝试使用[self.view drawViewHierarchyInRect:self.view.bounds afterScreenUpdates:YES];它似乎只是获得截图的不同方式。 – Idali 2014-09-29 10:56:06